Changeset 36211 in osm for applications
- Timestamp:
- 2024-02-21T22:06:26+01:00 (10 months ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/native-password-manager/build.xml
r36049 r36211 5 5 <property name="commit.message" value="Commit message"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="18 650"/>7 <property name="plugin.main.version" value="18991"/> 8 8 <property name="plugin.author" value="Paul Hartmann"/> 9 9 <property name="plugin.class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/> -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
r34599 r36211 41 41 42 42 import org.netbeans.spi.keyring.KeyringProvider; 43 import org.openstreetmap.josm.data.oauth.OAuthToken;44 43 import org.openstreetmap.josm.gui.MainApplication; 45 44 import org.openstreetmap.josm.gui.util.WindowGeometry; 46 45 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 47 46 import org.openstreetmap.josm.io.DefaultProxySelector; 48 import org.openstreetmap.josm.io.OsmApi;49 47 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 50 48 import org.openstreetmap.josm.io.auth.CredentialsManager; … … 56 54 public class InitializationWizard extends JDialog { 57 55 58 protected boolean canceled = false;56 protected boolean canceled; 59 57 protected JButton btnCancel, btnBack, btnNext; 60 58 protected Action nextAction, finishAction; … … 67 65 68 66 public InitializationWizard() { 69 super(JOptionPane.getFrameForComponent(MainApplication.getMainFrame()), tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL); 67 super(JOptionPane.getFrameForComponent(MainApplication.getMainFrame()), 68 tr("Native password manager plugin"), ModalityType.DOCUMENT_MODAL); 70 69 build(); 71 70 NPMType npm = detectNativePasswordManager(); … … 146 145 void onOkAction(); 147 146 } 148 149 abstract privatestatic class AbstractWizardPanel implements WizardPanel {147 148 private abstract static class AbstractWizardPanel implements WizardPanel { 150 149 151 150 /** … … 175 174 } 176 175 177 abstract protectedJPanel getContentPanel();176 protected abstract JPanel getContentPanel(); 178 177 } 179 178 … … 229 228 private static class SelectionPanel extends AbstractWizardPanel implements ActionListener { 230 229 231 private NPMType type;232 private InitializationWizard wizard;230 private final NPMType type; 231 private final InitializationWizard wizard; 233 232 234 233 private JRadioButton rbManage, rbPlain; … … 350 349 351 350 CredentialsManager cm = CredentialsManager.getInstance(); 352 353 String server_username = Config.getPref().get("osm-server.username", null); 354 String server_password = Config.getPref().get("osm-server.password", null); 355 if (server_username != null || server_password != null) { 351 352 String proxyUsername = Config.getPref().get(DefaultProxySelector.PROXY_USER, null); 353 String proxyPassword = Config.getPref().get(DefaultProxySelector.PROXY_PASS, null); 354 String proxyHost = Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, null); 355 if (proxyUsername != null || proxyPassword != null) { 356 356 try { 357 cm.store(RequestorType.SERVER, OsmApi.getOsmApi().getHost(), new PasswordAuthentication(string(server_username), toCharArray(server_password))); 358 if (rbClear.isSelected()) { 359 Config.getPref().put("osm-server.username", null); 360 Config.getPref().put("osm-server.password", null); 361 } 362 } catch (CredentialsAgentException ex) { 363 Logging.error(ex); 364 } 365 } 366 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 if (proxy_username != null || proxy_password != null) { 371 try { 372 cm.store(RequestorType.PROXY, proxy_host, new PasswordAuthentication(string(proxy_username), toCharArray(proxy_password))); 357 cm.store(RequestorType.PROXY, proxyHost, new PasswordAuthentication(string(proxyUsername), toCharArray(proxyPassword))); 373 358 if (rbClear.isSelected()) { 374 359 Config.getPref().put(DefaultProxySelector.PROXY_USER, null); … … 379 364 } 380 365 } 381 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 if (oauth_key != null || oauth_secret != null) { 385 try { 386 cm.storeOAuthAccessToken(new OAuthToken(string(oauth_key), string(oauth_secret))); 387 if (rbClear.isSelected()) { 388 Config.getPref().put("oauth.access-token.key", null); 389 Config.getPref().put("oauth.access-token.secret", null); 390 } 391 } catch (CredentialsAgentException ex) { 392 Logging.error(ex); 393 } 394 } 395 } 396 } 397 398 private final static String NPM = "Native Password Manager Plugin: "; 366 } 367 } 368 369 private static final String NPM = "Native Password Manager Plugin: "; 399 370 400 371 private static NPMType detectNativePasswordManager() { … … 445 416 ) 446 417 ).applySafe(this); 447 } else if ( !visible &&isShowing()){418 } else if (isShowing()){ 448 419 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 449 420 } … … 493 464 public void actionPerformed(ActionEvent evt) { 494 465 if (panelIndex <= 0) 495 throw new RuntimeException(); 466 // Java 9 will let us pass the panelIndex by itself 467 throw new IndexOutOfBoundsException("Index out of range: " + panelIndex); 496 468 panelIndex--; 497 469 cardLayout.show(cardPanel, panels.get(panelIndex).getId()); -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/NPMCredentialsAgent.java
r36049 r36211 25 25 import org.openstreetmap.josm.data.oauth.OAuth20Parameters; 26 26 import org.openstreetmap.josm.data.oauth.OAuth20Token; 27 import org.openstreetmap.josm.data.oauth.OAuthToken;28 27 import org.openstreetmap.josm.data.oauth.OAuthVersion; 29 28 import org.openstreetmap.josm.gui.widgets.HtmlPanel; … … 52 51 */ 53 52 private final Map<RequestorType, PasswordAuthentication> credentialsCache = new EnumMap<>(RequestorType.class); 54 private OAuthToken oauthCache; 53 55 54 56 55 /** … … 187 186 credentialsCache.put(rt, new PasswordAuthentication(stringNotNull(username), password != null ? password : new char[0])); 188 187 } 189 }190 191 @Override192 public OAuthToken lookupOAuthAccessToken() {193 if (oauthCache != null)194 return oauthCache;195 String prolog = getOAuthDescriptor();196 char[] key = getProvider().read(prolog+".key");197 char[] secret = getProvider().read(prolog+".secret");198 return new OAuthToken(stringNotNull(key), stringNotNull(secret));199 188 } 200 189 … … 223 212 224 213 @Override 225 public void storeOAuthAccessToken(OAuthToken oat) {226 String key, secret;227 if (oat == null) {228 key = null;229 secret = null;230 } else {231 key = oat.getKey();232 secret = oat.getSecret();233 }234 String prolog = getOAuthDescriptor();235 if (key == null || key.isEmpty() || secret == null || secret.isEmpty()) {236 getProvider().delete(prolog+".key");237 getProvider().delete(prolog+".secret");238 oauthCache = null;239 } else {240 getProvider().save(prolog+".key", key.toCharArray(), tr("JOSM/OAuth/OSM API/Key"));241 getProvider().save(prolog+".secret", secret.toCharArray(), tr("JOSM/OAuth/OSM API/Secret"));242 oauthCache = new OAuthToken(key, secret);243 }244 }245 246 @Override247 214 public void storeOAuthAccessToken(String host, IOAuthToken accessToken) { 248 215 String prolog = getOAuthDescriptor(); -
applications/editors/josm/plugins/sds/build.xml
r36051 r36211 5 5 <property name="commit.message" value=""/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="18 650"/>7 <property name="plugin.main.version" value="18991"/> 8 8 9 9 <property name="plugin.author" value="Frederik Ramm"/> -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialAgent.java
r36051 r36211 13 13 14 14 import org.openstreetmap.josm.data.oauth.IOAuthToken; 15 import org.openstreetmap.josm.data.oauth.OAuthToken;16 15 import org.openstreetmap.josm.gui.io.CredentialDialog; 17 16 import org.openstreetmap.josm.gui.widgets.HtmlPanel; … … 83 82 } 84 83 85 /**86 * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no87 * Access Token is currently managed by this CredentialManager.88 *89 * @return the current OAuth Access Token to access the OSM server.90 */91 @Override92 public OAuthToken lookupOAuthAccessToken() {93 String accessTokenKey = Config.getPref().get("oauth.access-token.key", null);94 String accessTokenSecret = Config.getPref().get("oauth.access-token.secret", null);95 if (accessTokenKey == null && accessTokenSecret == null)96 return null;97 return new OAuthToken(accessTokenKey, accessTokenSecret);98 }99 100 84 @Override 101 85 public IOAuthToken lookupOAuthAccessToken(String host) { … … 125 109 public String getSaveUsernameAndPasswordCheckboxText() { 126 110 return tr("Save user and password (unencrypted)"); 127 }128 129 @Override130 public void storeOAuthAccessToken(OAuthToken accessToken) {131 // no-op132 111 } 133 112
Note:
See TracChangeset
for help on using the changeset viewer.