Ignore:
Timestamp:
2011-07-18T13:13:10+02:00 (14 years ago)
Author:
bastik
Message:

make it work for windows

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  
    6060
    6161    private EncryptionProvider encryption;
    62     private IPreferences pre;
    63    
     62    private IPreferences prefs;
     63
    6464    // simple interface for a generic preferences store
    6565    public interface IPreferences {
    66         String get(String key, String def);
    67         void put(String key, String val);
     66        byte[] getByteArray(String key, byte[] def);
     67        void putByteArray(String key, byte[] val);
    6868        void remove(String key);
    6969    }
    7070
    71     public FallbackProvider(EncryptionProvider encryption, IPreferences pref) {
     71    public FallbackProvider(EncryptionProvider encryption, IPreferences prefs) {
    7272        this.encryption = encryption;
    73         this.pre = pref;
     73        this.prefs = prefs;
    7474    }
    75    
     75
    7676    public boolean enabled() {
    7777        if (encryption.enabled()) {
     
    9898
    9999    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);
    102101        if (ciphertext == null) {
    103102            return null;
     
    116115    private boolean _save(String key, char[] password, String description) {
    117116        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));
    121118        } catch (Exception x) {
    122119            LOG.log(Level.FINE, "failed to encrypt password for " + key, x);
    123120            return false;
    124         }
    125         if (description != null) {
    126             // Preferences interface gives no access to *.properties comments, so:
    127             pre.put(key + DESCRIPTION, description);
    128121        }
    129122        return true;
     
    131124
    132125    public void delete(String key) {
    133         pre.remove(key);
    134         pre.remove(key + DESCRIPTION);
     126        prefs.remove(key);
     127        prefs.remove(key + DESCRIPTION);
    135128    }
    136129
  • applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java

    r26355 r26361  
    399399        NPMType[] potentialManagers;
    400400       
    401         if (Main.platform instanceof PlatformHookUnixoid) {
    402             potentialManagers = new NPMType[] { NPMType.GNOME_KEYRING, NPMType.KWALLET };
     401        if (Main.platform instanceof PlatformHookWindows) {
     402            potentialManagers = new NPMType[] { NPMType.CRYPT32 };
    403403        } else if (Main.platform instanceof PlatformHookOsx) {
    404404            potentialManagers = new NPMType[] { NPMType.KEYCHAIN };
    405         } else if (Main.platform instanceof PlatformHookWindows) {
    406             potentialManagers = new NPMType[] { NPMType.CRYPT32 };
     405        } else if (Main.platform instanceof PlatformHookUnixoid) {
     406            potentialManagers = new NPMType[] { NPMType.GNOME_KEYRING, NPMType.KWALLET };
    407407        } else
    408408            throw new AssertionError();
  • applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/Win32Provider.java

    r26335 r26361  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.npm;
     3
     4import org.apache.commons.codec.binary.Base64;
    35
    46import org.netbeans.modules.keyring.fallback.FallbackProvider;
     
    911   
    1012    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);
    1317        }
    1418
    15         @Override public void put(String key, String val) {
    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));
    1721        }
    1822
Note: See TracChangeset for help on using the changeset viewer.