Changeset 26361 in osm for applications/editors/josm/plugins/native-password-manager/src/org
- Timestamp:
- 2011-07-18T13:13:10+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/native-password-manager/src/org
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java
r26335 r26361 60 60 61 61 private EncryptionProvider encryption; 62 private IPreferences pre; 63 62 private IPreferences prefs; 63 64 64 // simple interface for a generic preferences store 65 65 public interface IPreferences { 66 String get(String key,Stringdef);67 void put(String key, Stringval);66 byte[] getByteArray(String key, byte[] def); 67 void putByteArray(String key, byte[] val); 68 68 void remove(String key); 69 69 } 70 70 71 public FallbackProvider(EncryptionProvider encryption, IPreferences pref) { 71 public FallbackProvider(EncryptionProvider encryption, IPreferences prefs) { 72 72 this.encryption = encryption; 73 this.pre = pref;73 this.prefs = prefs; 74 74 } 75 75 76 76 public boolean enabled() { 77 77 if (encryption.enabled()) { … … 98 98 99 99 public char[] read(String key) { 100 String ciphertext_string = pre.get(key, null); 101 byte[] ciphertext = ciphertext_string == null ? null : Utils.chars2Bytes(ciphertext_string.toCharArray()); 100 byte[] ciphertext = prefs.getByteArray(key, null); 102 101 if (ciphertext == null) { 103 102 return null; … … 116 115 private boolean _save(String key, char[] password, String description) { 117 116 try { 118 byte[] encryptedPasswordByteArray = encryption.encrypt(password); 119 String encryptedPassword = encryptedPasswordByteArray == null ? null : String.valueOf(Utils.bytes2Chars(encryptedPasswordByteArray)); 120 pre.put(key, encryptedPassword); 117 prefs.putByteArray(key, encryption.encrypt(password)); 121 118 } catch (Exception x) { 122 119 LOG.log(Level.FINE, "failed to encrypt password for " + key, x); 123 120 return false; 124 }125 if (description != null) {126 // Preferences interface gives no access to *.properties comments, so:127 pre.put(key + DESCRIPTION, description);128 121 } 129 122 return true; … … 131 124 132 125 public void delete(String key) { 133 pre.remove(key); 134 pre.remove(key + DESCRIPTION); 126 prefs.remove(key); 127 prefs.remove(key + DESCRIPTION); 135 128 } 136 129 -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
r26355 r26361 399 399 NPMType[] potentialManagers; 400 400 401 if (Main.platform instanceof PlatformHook Unixoid) {402 potentialManagers = new NPMType[] { NPMType. GNOME_KEYRING, NPMType.KWALLET};401 if (Main.platform instanceof PlatformHookWindows) { 402 potentialManagers = new NPMType[] { NPMType.CRYPT32 }; 403 403 } else if (Main.platform instanceof PlatformHookOsx) { 404 404 potentialManagers = new NPMType[] { NPMType.KEYCHAIN }; 405 } else if (Main.platform instanceof PlatformHook Windows) {406 potentialManagers = new NPMType[] { NPMType. CRYPT32};405 } else if (Main.platform instanceof PlatformHookUnixoid) { 406 potentialManagers = new NPMType[] { NPMType.GNOME_KEYRING, NPMType.KWALLET }; 407 407 } else 408 408 throw new AssertionError(); -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/Win32Provider.java
r26335 r26361 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.npm; 3 4 import org.apache.commons.codec.binary.Base64; 3 5 4 6 import org.netbeans.modules.keyring.fallback.FallbackProvider; … … 9 11 10 12 private static class JOSMPreferences implements IPreferences { 11 @Override public String get(String key, String def) { 12 return Main.pref.get(key, def); 13 14 @Override public byte[] getByteArray(String key, byte[] def) { 15 String p = Main.pref.get(key, null); 16 return p == null ? def : Base64.decodeBase64(p); 13 17 } 14 18 15 @Override public void put(String key, Stringval) {16 Main.pref.put(key, val); 19 @Override public void putByteArray(String key, byte[] val) { 20 Main.pref.put(key, val == null ? null : Base64.encodeBase64String(val)); 17 21 } 18 22
Note:
See TracChangeset
for help on using the changeset viewer.