|
11 | 11 | import io.sloeber.core.common.Const;
|
12 | 12 |
|
13 | 13 | public class PasswordManager {
|
14 |
| - private String myPassword; |
15 |
| - private String myLogin = null; |
16 |
| - private String myhost = null; |
17 |
| - boolean ret = false; |
18 |
| - |
19 |
| - public PasswordManager() { |
20 |
| - // no constructor needed |
21 |
| - } |
22 |
| - |
23 |
| - public String getPassword() { |
24 |
| - return this.myPassword; |
25 |
| - } |
26 |
| - |
27 |
| - public String getLogin() { |
28 |
| - return this.myLogin; |
29 |
| - } |
30 |
| - |
31 |
| - public String getHost() { |
32 |
| - return this.myhost; |
33 |
| - } |
34 |
| - |
35 |
| - /** |
36 |
| - * Sets the host. If there is no Login,password for this host the method |
37 |
| - * returns false. If a login/password for the host is found the method |
38 |
| - * returns true |
39 |
| - * |
40 |
| - * @param host |
41 |
| - * @return |
42 |
| - */ |
43 |
| - public boolean setHost(String host) { |
44 |
| - this.myhost = host; |
45 |
| - this.myPassword = null; |
46 |
| - this.myLogin = null; |
47 |
| - |
48 |
| - String nodename = ConvertHostToNodeName(this.myhost); |
49 |
| - ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
50 |
| - |
51 |
| - try { |
52 |
| - if (root.nodeExists(nodename)) { |
53 |
| - |
54 |
| - ISecurePreferences node = root.node(nodename); |
55 |
| - this.myPassword = node.get(Messages.security_password, null); |
56 |
| - this.myLogin = node.get(Messages.security_login, null); |
57 |
| - return true; |
58 |
| - } |
59 |
| - |
60 |
| - } catch (StorageException e) { |
61 |
| - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, |
62 |
| - "Set a password on the project properties->arduino page", e)); //$NON-NLS-1$ |
63 |
| - } |
64 |
| - |
65 |
| - return false; |
66 |
| - } |
67 |
| - |
68 |
| - /** |
69 |
| - * Sets the login and password for a host |
70 |
| - * |
71 |
| - * @param host |
72 |
| - * @param login |
73 |
| - * @param password |
74 |
| - * @throws Exception |
75 |
| - */ |
76 |
| - public void setLoginData(String host, String login, String password) throws Exception { |
77 |
| - this.myhost = host; |
78 |
| - this.myLogin = login; |
79 |
| - this.myPassword = password; |
80 |
| - String nodename = ConvertHostToNodeName(this.myhost); |
81 |
| - ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
82 |
| - ISecurePreferences node = root.node(nodename); |
83 |
| - |
84 |
| - node.put(Messages.security_login, this.myLogin, false); |
85 |
| - node.put(Messages.security_password, this.myPassword, true); |
86 |
| - } |
87 |
| - |
88 |
| - static public void setPwd(String host, String login, String pwd) { |
89 |
| - |
90 |
| - String nodename = ConvertHostToNodeName(host); |
91 |
| - ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
92 |
| - ISecurePreferences node = root.node(nodename); |
93 |
| - |
94 |
| - try { |
95 |
| - node.put(Messages.security_login, login, false); |
96 |
| - node.put(Messages.security_password, pwd, false); |
97 |
| - } catch (StorageException e) { |
98 |
| - |
99 |
| - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to set login info", e)); //$NON-NLS-1$ |
100 |
| - } |
101 |
| - |
102 |
| - } |
103 |
| - |
104 |
| - public static void ErasePassword(String host) { |
105 |
| - String nodename = ConvertHostToNodeName(host); |
106 |
| - ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
107 |
| - |
108 |
| - if (root.nodeExists(nodename)) { |
109 |
| - ISecurePreferences node = root.node(nodename); |
110 |
| - node.removeNode();// (Messages.security_password, null, true); |
111 |
| - } |
112 |
| - |
113 |
| - } |
114 |
| - |
115 |
| - private static String ConvertHostToNodeName(String host) { |
116 |
| - |
117 |
| - return "ssh/" + host.replace(Const.DOT, Const.SLACH); //$NON-NLS-1$ |
118 |
| - } |
| 14 | + private String myPassword; |
| 15 | + private String myLogin = null; |
| 16 | + private String myhost = null; |
| 17 | + boolean ret = false; |
| 18 | + |
| 19 | + public PasswordManager() { |
| 20 | + // no constructor needed |
| 21 | + } |
| 22 | + |
| 23 | + public String getPassword() { |
| 24 | + return this.myPassword; |
| 25 | + } |
| 26 | + |
| 27 | + public String getLogin() { |
| 28 | + return this.myLogin; |
| 29 | + } |
| 30 | + |
| 31 | + public String getHost() { |
| 32 | + return this.myhost; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Sets the host. If there is no Login,password for this host the method |
| 37 | + * returns false. If a login/password for the host is found the method |
| 38 | + * returns true |
| 39 | + * |
| 40 | + * @param host |
| 41 | + * @return |
| 42 | + */ |
| 43 | + public boolean setHost(String host) { |
| 44 | + this.myhost = host; |
| 45 | + this.myPassword = null; |
| 46 | + this.myLogin = null; |
| 47 | + |
| 48 | + String nodename = ConvertHostToNodeName(this.myhost); |
| 49 | + ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
| 50 | + |
| 51 | + try { |
| 52 | + if (root.nodeExists(nodename)) { |
| 53 | + |
| 54 | + ISecurePreferences node = root.node(nodename); |
| 55 | + this.myPassword = node.get(Messages.security_password, null); |
| 56 | + this.myLogin = node.get(Messages.security_login, null); |
| 57 | + return true; |
| 58 | + } |
| 59 | + |
| 60 | + } catch (StorageException e) { |
| 61 | + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, |
| 62 | + "Set a password on the project properties->Sloeber page", e)); //$NON-NLS-1$ |
| 63 | + } |
| 64 | + |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Sets the login and password for a host |
| 70 | + * |
| 71 | + * @param host |
| 72 | + * @param login |
| 73 | + * @param password |
| 74 | + * @throws Exception |
| 75 | + */ |
| 76 | + public void setLoginData(String host, String login, String password) throws Exception { |
| 77 | + this.myhost = host; |
| 78 | + this.myLogin = login; |
| 79 | + this.myPassword = password; |
| 80 | + String nodename = ConvertHostToNodeName(this.myhost); |
| 81 | + ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
| 82 | + ISecurePreferences node = root.node(nodename); |
| 83 | + |
| 84 | + node.put(Messages.security_login, this.myLogin, false); |
| 85 | + node.put(Messages.security_password, this.myPassword, true); |
| 86 | + } |
| 87 | + |
| 88 | + static public void setPwd(String host, String login, String pwd) { |
| 89 | + |
| 90 | + String nodename = ConvertHostToNodeName(host); |
| 91 | + ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
| 92 | + ISecurePreferences node = root.node(nodename); |
| 93 | + |
| 94 | + try { |
| 95 | + node.put(Messages.security_login, login, false); |
| 96 | + node.put(Messages.security_password, pwd, false); |
| 97 | + } catch (StorageException e) { |
| 98 | + |
| 99 | + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to set login info", e)); //$NON-NLS-1$ |
| 100 | + } |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + public static void ErasePassword(String host) { |
| 105 | + String nodename = ConvertHostToNodeName(host); |
| 106 | + ISecurePreferences root = SecurePreferencesFactory.getDefault(); |
| 107 | + |
| 108 | + if (root.nodeExists(nodename)) { |
| 109 | + ISecurePreferences node = root.node(nodename); |
| 110 | + node.removeNode();// (Messages.security_password, null, true); |
| 111 | + } |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + private static String ConvertHostToNodeName(String host) { |
| 116 | + |
| 117 | + return "ssh/" + host.replace(Const.DOT, Const.SLACH); //$NON-NLS-1$ |
| 118 | + } |
119 | 119 |
|
120 | 120 | }
|
0 commit comments