Changeset 34472 in osm for applications/editors/josm/plugins/native-password-manager/src
- Timestamp:
- 2018-08-15T02:15:59+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
r33587 r34472 41 41 42 42 import org.netbeans.spi.keyring.KeyringProvider; 43 import org.openstreetmap.josm.Main;44 43 import org.openstreetmap.josm.data.oauth.OAuthToken; 44 import org.openstreetmap.josm.gui.MainApplication; 45 45 import org.openstreetmap.josm.gui.util.WindowGeometry; 46 46 import org.openstreetmap.josm.gui.widgets.HtmlPanel; … … 49 49 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 50 50 import org.openstreetmap.josm.io.auth.CredentialsManager; 51 import org.openstreetmap.josm.spi.preferences.Config; 51 52 import org.openstreetmap.josm.tools.ImageProvider; 52 import org.openstreetmap.josm.tools.PlatformHookOsx; 53 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 54 import org.openstreetmap.josm.tools.PlatformHookWindows; 53 import org.openstreetmap.josm.tools.Logging; 54 import org.openstreetmap.josm.tools.PlatformManager; 55 55 56 56 public class InitializationWizard extends JDialog { … … 67 67 68 68 public InitializationWizard() { 69 super(JOptionPane.getFrameForComponent(Main .parent), tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL);69 super(JOptionPane.getFrameForComponent(MainApplication.getMainFrame()), tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL); 70 70 build(); 71 71 NPMType npm = detectNativePasswordManager(); … … 351 351 CredentialsManager cm = CredentialsManager.getInstance(); 352 352 353 String server_username = Main.pref.get("osm-server.username", null);354 String server_password = Main.pref.get("osm-server.password", null);353 String server_username = Config.getPref().get("osm-server.username", null); 354 String server_password = Config.getPref().get("osm-server.password", null); 355 355 if (server_username != null || server_password != null) { 356 356 try { 357 357 cm.store(RequestorType.SERVER, OsmApi.getOsmApi().getHost(), new PasswordAuthentication(string(server_username), toCharArray(server_password))); 358 358 if (rbClear.isSelected()) { 359 Main.pref.put("osm-server.username", null);360 Main.pref.put("osm-server.password", null);359 Config.getPref().put("osm-server.username", null); 360 Config.getPref().put("osm-server.password", null); 361 361 } 362 362 } catch (CredentialsAgentException ex) { … … 365 365 } 366 366 367 String proxy_username = Main.pref.get(DefaultProxySelector.PROXY_USER, null);368 String proxy_password = Main.pref.get(DefaultProxySelector.PROXY_PASS, null);369 String proxy_host = Main.pref.get(DefaultProxySelector.PROXY_HTTP_HOST, null);367 String proxy_username = Config.getPref().get(DefaultProxySelector.PROXY_USER, null); 368 String proxy_password = Config.getPref().get(DefaultProxySelector.PROXY_PASS, null); 369 String proxy_host = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, null); 370 370 if (proxy_username != null || proxy_password != null) { 371 371 try { 372 372 cm.store(RequestorType.PROXY, proxy_host, new PasswordAuthentication(string(proxy_username), toCharArray(proxy_password))); 373 373 if (rbClear.isSelected()) { 374 Main.pref.put(DefaultProxySelector.PROXY_USER, null);375 Main.pref.put(DefaultProxySelector.PROXY_PASS, null);374 Config.getPref().put(DefaultProxySelector.PROXY_USER, null); 375 Config.getPref().put(DefaultProxySelector.PROXY_PASS, null); 376 376 } 377 377 } catch (CredentialsAgentException ex) { … … 380 380 } 381 381 382 String oauth_key = Main.pref.get("oauth.access-token.key", null);383 String oauth_secret = Main.pref.get("oauth.access-token.secret", null);382 String oauth_key = Config.getPref().get("oauth.access-token.key", null); 383 String oauth_secret = Config.getPref().get("oauth.access-token.secret", null); 384 384 if (oauth_key != null || oauth_secret != null) { 385 385 try { 386 386 cm.storeOAuthAccessToken(new OAuthToken(string(oauth_key), string(oauth_secret))); 387 387 if (rbClear.isSelected()) { 388 Main.pref.put("oauth.access-token.key", null);389 Main.pref.put("oauth.access-token.secret", null);388 Config.getPref().put("oauth.access-token.key", null); 389 Config.getPref().put("oauth.access-token.secret", null); 390 390 } 391 391 } catch (CredentialsAgentException ex) { … … 400 400 private static NPMType detectNativePasswordManager() { 401 401 NPMType[] potentialManagers; 402 403 if (Main.platform instanceof PlatformHookWindows) { 402 if (PlatformManager.isPlatformWindows()) { 404 403 potentialManagers = new NPMType[] { NPMType.CRYPT32 }; 405 } else if ( Main.platform instanceof PlatformHookOsx) {404 } else if (PlatformManager.isPlatformOsx()) { 406 405 potentialManagers = new NPMType[] { NPMType.KEYCHAIN }; 407 } else if ( Main.platform instanceof PlatformHookUnixoid) {406 } else if (PlatformManager.isPlatformUnixoid()) { 408 407 potentialManagers = new NPMType[] { NPMType.GNOME_KEYRING, NPMType.KWALLET }; 409 408 } else 410 409 throw new AssertionError(); 411 410 412 411 for (NPMType manager : potentialManagers) { 413 System.out.println(NPM + "Looking for " + manager.getName());412 Logging.info(NPM + "Looking for " + manager.getName()); 414 413 KeyringProvider provider = manager.getProvider(); 415 414 if (provider.enabled()) { 416 System.out.println(NPM + "Found " + manager.getName());415 Logging.info(NPM + "Found " + manager.getName()); 417 416 return manager; 418 417 } … … 423 422 private static boolean hasUnprotectedCedentials() { 424 423 return 425 Main.pref.get("osm-server.username", null) != null ||426 Main.pref.get("osm-server.password", null) != null ||427 Main.pref.get(DefaultProxySelector.PROXY_USER, null) != null ||428 Main.pref.get(DefaultProxySelector.PROXY_PASS, null) != null ||429 Main.pref.get("oauth.access-token.key", null) != null ||430 Main.pref.get("oauth.access-token.secret", null) != null;424 Config.getPref().get("osm-server.username", null) != null || 425 Config.getPref().get("osm-server.password", null) != null || 426 Config.getPref().get(DefaultProxySelector.PROXY_USER, null) != null || 427 Config.getPref().get(DefaultProxySelector.PROXY_PASS, null) != null || 428 Config.getPref().get("oauth.access-token.key", null) != null || 429 Config.getPref().get("oauth.access-token.secret", null) != null; 431 430 } 432 431 -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/NPMCredentialsAgent.java
r33587 r34472 16 16 17 17 import org.netbeans.spi.keyring.KeyringProvider; 18 import org.openstreetmap.josm. Main;18 import org.openstreetmap.josm.data.Preferences; 19 19 import org.openstreetmap.josm.data.oauth.OAuthToken; 20 20 import org.openstreetmap.josm.gui.widgets.HtmlPanel; … … 23 23 import org.openstreetmap.josm.io.auth.AbstractCredentialsAgent; 24 24 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 25 import org.openstreetmap.josm.spi.preferences.Config; 25 26 import org.openstreetmap.josm.tools.Utils; 26 27 … … 54 55 55 56 protected String getServerDescriptor() { 56 String pref = Main.pref.getPreferenceFile().getAbsolutePath();57 58 String url = Main.pref.get("osm-server.url", null);57 String pref = Preferences.main().getPreferenceFile().getAbsolutePath(); 58 59 String url = Config.getPref().get("osm-server.url", null); 59 60 if (url == null) { 60 url = OsmApi.DEFAULT_API_URL;61 url = Config.getUrls().getDefaultOsmApiUrl(); 61 62 } 62 63 … … 70 71 71 72 protected String getProxyDescriptor() { 72 String pref = Main.pref.getPreferenceFile().getAbsolutePath();73 String host = Main.pref.get(DefaultProxySelector.PROXY_HTTP_HOST, "");74 String port = Main.pref.get(DefaultProxySelector.PROXY_HTTP_PORT, "");73 String pref = Preferences.main().getPreferenceFile().getAbsolutePath(); 74 String host = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, ""); 75 String port = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_PORT, ""); 75 76 76 77 CRC32 id = new CRC32(); … … 83 84 84 85 protected String getOAuthDescriptor() { 85 String pref = Main.pref.getPreferenceFile().getAbsolutePath();86 String pref = Preferences.main().getPreferenceFile().getAbsolutePath(); 86 87 // TODO: put more identifying data here 87 88 … … 224 225 ); 225 226 List<String> sensitive = new ArrayList<>(); 226 if ( Main.pref.get("osm-server.username", null) != null) {227 if (Config.getPref().get("osm-server.username", null) != null) { 227 228 sensitive.add(tr("username")); 228 229 } 229 if ( Main.pref.get("osm-server.password", null) != null) {230 if (Config.getPref().get("osm-server.password", null) != null) { 230 231 sensitive.add(tr("password")); 231 232 } 232 if ( Main.pref.get(DefaultProxySelector.PROXY_USER, null) != null) {233 if (Config.getPref().get(DefaultProxySelector.PROXY_USER, null) != null) { 233 234 sensitive.add(tr("proxy username")); 234 235 } 235 if ( Main.pref.get(DefaultProxySelector.PROXY_PASS, null) != null) {236 if (Config.getPref().get(DefaultProxySelector.PROXY_PASS, null) != null) { 236 237 sensitive.add(tr("proxy password")); 237 238 } 238 if ( Main.pref.get("oauth.access-token.key", null) != null) {239 if (Config.getPref().get("oauth.access-token.key", null) != null) { 239 240 sensitive.add(tr("oauth key")); 240 241 } 241 if ( Main.pref.get("oauth.access-token.secret", null) != null) {242 if (Config.getPref().get("oauth.access-token.secret", null) != null) { 242 243 sensitive.add(tr("oauth secret")); 243 244 } -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/NPMPlugin.java
r31665 r34472 5 5 6 6 import javax.swing.SwingUtilities; 7 import org.openstreetmap.josm.Main; 7 8 8 import org.openstreetmap.josm.io.auth.CredentialsManager; 9 10 9 import org.openstreetmap.josm.plugins.Plugin; 11 10 import org.openstreetmap.josm.plugins.PluginInformation; 11 import org.openstreetmap.josm.spi.preferences.Config; 12 12 13 13 public class NPMPlugin extends Plugin { … … 21 21 22 22 private void initialize() { 23 String pref = Main.pref.get(NPMPLUGIN_KEY+"agent", null);23 String pref = Config.getPref().get(NPMPLUGIN_KEY+"agent", null); 24 24 if ("off".equals(pref)) return; 25 25 NPMType sel = NPMType.fromPrefString(pref); … … 43 43 new NPMCredentialsAgentFactory(type) 44 44 ); 45 Main.pref.put(NPMPLUGIN_KEY+"agent", type.toPrefString());45 Config.getPref().put(NPMPLUGIN_KEY+"agent", type.toPrefString()); 46 46 } 47 47 48 48 public static void turnOffPermanently() { 49 Main.pref.put(NPMPLUGIN_KEY+"agent", "off");49 Config.getPref().put(NPMPLUGIN_KEY+"agent", "off"); 50 50 } 51 51 } -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/NPMType.java
r33587 r34472 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.npm; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.util.Objects; … … 9 11 import org.netbeans.spi.keyring.KeyringProvider; 10 12 import org.openstreetmap.josm.tools.JosmRuntimeException; 11 12 import static org.openstreetmap.josm.tools.I18n.tr;13 13 14 14 public enum NPMType { -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/Win32Provider.java
r34447 r34472 4 4 import org.netbeans.modules.keyring.fallback.FallbackProvider; 5 5 import org.netbeans.modules.keyring.win32.Win32Protect; 6 import org.openstreetmap.josm. Main;6 import org.openstreetmap.josm.spi.preferences.Config; 7 7 8 8 public class Win32Provider extends FallbackProvider { … … 11 11 12 12 @Override public byte[] getByteArray(String key, byte[] def) { 13 String p = Main.pref.get(key, null);13 String p = Config.getPref().get(key, null); 14 14 return p == null ? def : DatatypeConverter._parseBase64Binary(p); 15 15 } 16 16 17 17 @Override public void putByteArray(String key, byte[] val) { 18 Main.pref.put(key, val == null ? null : DatatypeConverter._printBase64Binary(val));18 Config.getPref().put(key, val == null ? null : DatatypeConverter._printBase64Binary(val)); 19 19 } 20 20 21 21 @Override public void remove(String key) { 22 Main.pref.put(key, null);22 Config.getPref().put(key, null); 23 23 } 24 24 }
Note:
See TracChangeset
for help on using the changeset viewer.