Changeset 18991 in josm for trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
- Timestamp:
- 2024-02-21T21:26:18+01:00 (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
r18828 r18991 39 39 /** indicates whether we use basic authentication */ 40 40 private final JRadioButton rbBasicAuthentication = new JRadioButton(); 41 /** indicates whether we use OAuth 1.0a as authentication scheme */42 private final JRadioButton rbOAuth = new JRadioButton();43 41 /** indicates whether we use OAuth 2.0 as authentication scheme */ 44 42 private final JRadioButton rbOAuth20 = new JRadioButton(); … … 47 45 /** the panel for the basic authentication parameters */ 48 46 private BasicAuthenticationPreferencesPanel pnlBasicAuthPreferences; 49 /** the panel for the OAuth 1.0a authentication parameters */50 private OAuthAuthenticationPreferencesPanel pnlOAuthPreferences;51 47 /** the panel for the OAuth 2.0 authentication parameters */ 52 48 private OAuthAuthenticationPreferencesPanel pnlOAuth20Preferences; … … 59 55 final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl); 60 56 rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || isExpert || !defaultApi); 61 rbOAuth.setEnabled(rbOAuth.isSelected() || "oauth".equals(authMethod) || isExpert || !defaultApi);62 57 }; 63 58 … … 85 80 rbBasicAuthentication.setToolTipText(tr("Select to use HTTP basic authentication with your OSM username and password")); 86 81 rbBasicAuthentication.addItemListener(authChangeListener); 87 88 //-- radio button for OAuth 1.0a89 buttonPanel.add(rbOAuth);90 rbOAuth.setText(tr("Use OAuth {0}", "1.0a"));91 rbOAuth.setToolTipText(tr("Select to use OAuth {0} as authentication mechanism", "1.0a"));92 rbOAuth.addItemListener(authChangeListener);93 94 82 //-- radio button for OAuth 2.0 95 83 buttonPanel.add(rbOAuth20); 84 rbOAuth20.setSelected(true); // This must before adding the listener; otherwise, saveToPreferences is called prior to initFromPreferences 96 85 rbOAuth20.setText(tr("Use OAuth {0}", "2.0")); 97 86 rbOAuth20.setToolTipText(tr("Select to use OAuth {0} as authentication mechanism", "2.0")); … … 102 91 ButtonGroup bg = new ButtonGroup(); 103 92 bg.add(rbBasicAuthentication); 104 bg.add(rbOAuth);105 93 bg.add(rbOAuth20); 106 94 … … 119 107 //-- the two panels for authentication parameters 120 108 pnlBasicAuthPreferences = new BasicAuthenticationPreferencesPanel(); 121 pnlOAuthPreferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth10a);122 109 pnlOAuth20Preferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth20); 123 110 124 111 ExpertToggleAction.addExpertModeChangeListener(expertModeChangeListener, true); 125 112 126 rbOAuth20.setSelected(true);127 113 pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER); 128 114 } … … 133 119 public final void initFromPreferences() { 134 120 final String authMethod = OsmApi.getAuthMethod(); 135 switch (authMethod) { 136 case "basic": 137 rbBasicAuthentication.setSelected(true); 138 break; 139 case "oauth": 140 rbOAuth.setSelected(true); 141 break; 142 case "oauth20": 143 rbOAuth20.setSelected(true); 144 break; 145 default: 146 Logging.warn(tr("Unsupported value in preference ''{0}'', got ''{1}''. Using authentication method ''Basic Authentication''.", 147 "osm-server.auth-method", authMethod)); 148 rbBasicAuthentication.setSelected(true); 121 if ("basic".equals(authMethod)) { 122 rbBasicAuthentication.setSelected(true); 123 } else if ("oauth20".equals(authMethod)) { 124 rbOAuth20.setSelected(true); 125 } else { 126 Logging.warn( 127 tr("Unsupported value in preference ''{0}'', got ''{1}''. Using authentication method ''OAuth 2.0 Authentication''.", 128 "osm-server.auth-method", authMethod)); 129 rbOAuth20.setSelected(true); 149 130 } 150 131 pnlBasicAuthPreferences.initFromPreferences(); 151 pnlOAuthPreferences.initFromPreferences();152 132 pnlOAuth20Preferences.initFromPreferences(); 153 133 } … … 161 141 if (rbBasicAuthentication.isSelected()) { 162 142 authMethod = "basic"; 163 } else if (rbOAuth.isSelected()) {164 authMethod = "oauth";165 143 } else if (rbOAuth20.isSelected()) { 166 144 authMethod = "oauth20"; … … 174 152 OAuthAccessTokenHolder.getInstance().clear(); 175 153 OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance()); 176 } else if ("oauth".equals(authMethod)) { 154 } else if ("oauth20".equals(authMethod)) { 155 // oauth20 177 156 // clear the password in the preferences 178 157 pnlBasicAuthPreferences.clearPassword(); 179 pnlBasicAuthPreferences.saveToPreferences();180 pnlOAuthPreferences.saveToPreferences();181 } else { // oauth20182 // clear the password in the preferences183 pnlBasicAuthPreferences.clearPassword();184 pnlBasicAuthPreferences.saveToPreferences();185 158 pnlOAuth20Preferences.saveToPreferences(); 186 159 } … … 188 161 if ("basic".equals(authMethod)) { 189 162 UserIdentityManager.getInstance().initFromPreferences(); 163 } else if (OsmApi.isUsingOAuthAndOAuthSetUp(OsmApi.getOsmApi())) { 164 UserIdentityManager.getInstance().initFromOAuth(); 190 165 } else { 191 UserIdentityManager.getInstance(). initFromOAuth();166 UserIdentityManager.getInstance().setAnonymous(); 192 167 } 193 168 } … … 205 180 pnlAuthenticationParameters.add(pnlBasicAuthPreferences, BorderLayout.CENTER); 206 181 pnlBasicAuthPreferences.revalidate(); 207 } else if (rbOAuth.isSelected()) {208 pnlAuthenticationParameters.add(pnlOAuthPreferences, BorderLayout.CENTER);209 pnlOAuthPreferences.saveToPreferences();210 pnlOAuthPreferences.initFromPreferences();211 pnlOAuthPreferences.revalidate();212 182 } else if (rbOAuth20.isSelected()) { 213 183 pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER); … … 222 192 @Override 223 193 public void propertyChange(PropertyChangeEvent evt) { 224 if (pnlOAuthPreferences != null) {225 pnlOAuthPreferences.propertyChange(evt);226 }227 194 if (pnlOAuth20Preferences != null) { 228 195 pnlOAuth20Preferences.propertyChange(evt);
Note:
See TracChangeset
for help on using the changeset viewer.