- Timestamp:
- 2017-10-06T15:17:51+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/oauth/OAuthAccessTokenHolder.java
r12841 r12928 7 7 import org.openstreetmap.josm.io.auth.CredentialsAgent; 8 8 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 9 import org.openstreetmap.josm.spi.preferences.Config; 9 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 10 11 import org.openstreetmap.josm.tools.Logging; … … 143 144 * credential manager. 144 145 * 146 * @param cm the credential manager. Must not be null. 147 * @throws IllegalArgumentException if cm is null 148 */ 149 public void init(CredentialsAgent cm) { 150 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); 151 OAuthToken token = null; 152 try { 153 token = cm.lookupOAuthAccessToken(); 154 } catch (CredentialsAgentException e) { 155 Logging.error(e); 156 Logging.warn(tr("Failed to retrieve OAuth Access Token from credential manager")); 157 Logging.warn(tr("Current credential manager is of type ''{0}''", cm.getClass().getName())); 158 } 159 saveToPreferences = Config.getPref().getBoolean("oauth.access-token.save-to-preferences", true); 160 if (token != null) { 161 accessTokenKey = token.getKey(); 162 accessTokenSecret = token.getSecret(); 163 } 164 } 165 166 /** 167 * Initializes the content of this holder from the Access Token managed by the 168 * credential manager. 169 * 145 170 * @param pref the preferences. Must not be null. 146 171 * @param cm the credential manager. Must not be null. 147 172 * @throws IllegalArgumentException if cm is null 148 */ 173 * @deprecated (since 12928) replaced by {@link #init(org.openstreetmap.josm.io.auth.CredentialsAgent)} 174 */ 175 @Deprecated 149 176 public void init(Preferences pref, CredentialsAgent cm) { 150 177 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); … … 169 196 * by a credential manager. 170 197 * 171 * @param preferences the preferences. Must not be null.172 198 * @param cm the credentials manager. Must not be null. 173 * @throws IllegalArgumentException if preferences is null 174 * @throws IllegalArgumentException if cm is null 175 */ 176 public void save(Preferences preferences, CredentialsAgent cm) { 177 CheckParameterUtil.ensureParameterNotNull(preferences, "preferences"); 178 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); 179 preferences.putBoolean("oauth.access-token.save-to-preferences", saveToPreferences); 199 * @throws IllegalArgumentException if cm is null 200 */ 201 public void save(CredentialsAgent cm) { 202 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); 203 Config.getPref().putBoolean("oauth.access-token.save-to-preferences", saveToPreferences); 180 204 try { 181 205 if (!saveToPreferences) { … … 192 216 193 217 /** 218 * Saves the content of this holder to the preferences and a credential store managed 219 * by a credential manager. 220 * 221 * @param preferences the preferences. Must not be null. 222 * @param cm the credentials manager. Must not be null. 223 * @throws IllegalArgumentException if preferences is null 224 * @throws IllegalArgumentException if cm is null 225 * @deprecated (since 12928) replaced by {@link #save(org.openstreetmap.josm.io.auth.CredentialsAgent)} 226 */ 227 @Deprecated 228 public void save(Preferences preferences, CredentialsAgent cm) { 229 CheckParameterUtil.ensureParameterNotNull(preferences, "preferences"); 230 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); 231 preferences.putBoolean("oauth.access-token.save-to-preferences", saveToPreferences); 232 try { 233 if (!saveToPreferences) { 234 cm.storeOAuthAccessToken(null); 235 } else { 236 cm.storeOAuthAccessToken(new OAuthToken(accessTokenKey, accessTokenSecret)); 237 } 238 } catch (CredentialsAgentException e) { 239 Logging.error(e); 240 Logging.warn(tr("Failed to store OAuth Access Token to credentials manager")); 241 Logging.warn(tr("Current credential manager is of type ''{0}''", cm.getClass().getName())); 242 } 243 } 244 245 /** 194 246 * Clears the content of this holder 195 247 */ -
trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java
r10294 r12928 7 7 import org.openstreetmap.josm.data.Preferences; 8 8 import org.openstreetmap.josm.io.OsmApi; 9 import org.openstreetmap.josm.spi.preferences.Config; 9 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 10 11 import org.openstreetmap.josm.tools.Utils; … … 79 80 * Replies a set of parameters as defined in the preferences. 80 81 * 82 * @param apiUrl the API URL. Must not be null. 83 * @return the parameters 84 */ 85 public static OAuthParameters createFromApiUrl(String apiUrl) { 86 OAuthParameters parameters = createDefault(apiUrl); 87 return new OAuthParameters( 88 Config.getPref().get("oauth.settings.consumer-key", parameters.getConsumerKey()), 89 Config.getPref().get("oauth.settings.consumer-secret", parameters.getConsumerSecret()), 90 Config.getPref().get("oauth.settings.request-token-url", parameters.getRequestTokenUrl()), 91 Config.getPref().get("oauth.settings.access-token-url", parameters.getAccessTokenUrl()), 92 Config.getPref().get("oauth.settings.authorise-url", parameters.getAuthoriseUrl()), 93 Config.getPref().get("oauth.settings.osm-login-url", parameters.getOsmLoginUrl()), 94 Config.getPref().get("oauth.settings.osm-logout-url", parameters.getOsmLogoutUrl())); 95 } 96 97 /** 98 * Replies a set of parameters as defined in the preferences. 99 * 81 100 * @param pref the preferences 82 101 * @return the parameters 83 */ 102 * @deprecated (since 12928) replaced by {@link #createFromApiUrl(java.lang.String)} 103 */ 104 @Deprecated 84 105 public static OAuthParameters createFromPreferences(Preferences pref) { 85 106 OAuthParameters parameters = createDefault(pref.get("osm-server.url")); … … 95 116 96 117 /** 118 * Remembers the current values in the preferences. 119 */ 120 public void rememberPreferences() { 121 Config.getPref().put("oauth.settings.consumer-key", getConsumerKey()); 122 Config.getPref().put("oauth.settings.consumer-secret", getConsumerSecret()); 123 Config.getPref().put("oauth.settings.request-token-url", getRequestTokenUrl()); 124 Config.getPref().put("oauth.settings.access-token-url", getAccessTokenUrl()); 125 Config.getPref().put("oauth.settings.authorise-url", getAuthoriseUrl()); 126 Config.getPref().put("oauth.settings.osm-login-url", getOsmLoginUrl()); 127 Config.getPref().put("oauth.settings.osm-logout-url", getOsmLogoutUrl()); 128 } 129 130 /** 97 131 * Remembers the current values in the preferences <code>pref</code>. 98 132 * 99 133 * @param pref the preferences. Must not be null. 100 134 * @throws IllegalArgumentException if pref is null. 101 */ 135 * @deprecated (since 12928) replaced by {@link #rememberPreferences()} 136 */ 137 @Deprecated 102 138 public void rememberPreferences(Preferences pref) { 103 139 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); … … 129 165 * @param osmLogoutUrl the OSM logout URL (for automatic mode) 130 166 * @see #createDefault 131 * @see #createFrom Preferences167 * @see #createFromApiUrl 132 168 * @since 9220 133 169 */ -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12923 r12928 981 981 DefaultProxySelector proxySelector = new DefaultProxySelector(ProxySelector.getDefault()); 982 982 ProxySelector.setDefault(proxySelector); 983 OAuthAccessTokenHolder.getInstance().init( Main.pref,CredentialsManager.getInstance());983 OAuthAccessTokenHolder.getInstance().init(CredentialsManager.getInstance()); 984 984 985 985 setupCallbacks(); -
trunk/src/org/openstreetmap/josm/gui/oauth/AbstractAuthorizationUI.java
r10378 r12928 130 130 131 131 /** 132 * Initializes the authorisation UI. 133 * 134 * @param paramApiUrl the API URL. Must not be null. 135 * @throws IllegalArgumentException if paramApiUrl is null 136 */ 137 public void initialize(String paramApiUrl) { 138 CheckParameterUtil.ensureParameterNotNull(paramApiUrl, "paramApiUrl"); 139 pnlAdvancedProperties.initialize(paramApiUrl); 140 } 141 142 /** 132 143 * Initializes the authorisation UI with preference values in <code>pref</code>. 133 144 * 134 145 * @param pref the preferences. Must not be null. 135 146 * @throws IllegalArgumentException if pref is null 147 * @deprecated (since 12928) replaced by {@link #initialize(java.lang.String)} 136 148 */ 149 @Deprecated 137 150 public void initFromPreferences(Preferences pref) { 138 151 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); -
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r12841 r12928 24 24 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 25 25 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 26 import org.openstreetmap.josm.spi.preferences.Config; 26 27 import org.openstreetmap.josm.tools.CheckParameterUtil; 27 28 import org.openstreetmap.josm.tools.ImageProvider; … … 257 258 * Initializes the panel from the values in the preferences <code>preferences</code>. 258 259 * 260 * @param paramApiUrl the API URL. Must not be null. 261 * @throws IllegalArgumentException if paramApiUrl is null 262 */ 263 public void initialize(String paramApiUrl) { 264 CheckParameterUtil.ensureParameterNotNull(paramApiUrl, "paramApiUrl"); 265 setApiUrl(paramApiUrl); 266 boolean useDefault = Config.getPref().getBoolean("oauth.settings.use-default", true); 267 ilUseDefault.setEnabled(false); 268 if (useDefault) { 269 resetToDefaultSettings(); 270 } else { 271 setAdvancedParameters(OAuthParameters.createFromApiUrl(paramApiUrl)); 272 } 273 ilUseDefault.setEnabled(true); 274 } 275 276 /** 277 * Initializes the panel from the values in the preferences <code>preferences</code>. 278 * 259 279 * @param pref the preferences. Must not be null. 260 280 * @throws IllegalArgumentException if pref is null 261 */ 281 * @deprecated (since 12928) replaced by {@link #initialize(java.lang.String)} 282 */ 283 @Deprecated 262 284 public void initFromPreferences(Preferences pref) { 263 285 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); … … 275 297 /** 276 298 * Remembers the current values in the preferences <code>pref</code>. 299 */ 300 public void rememberPreferences() { 301 Config.getPref().putBoolean("oauth.settings.use-default", cbUseDefaults.isSelected()); 302 if (cbUseDefaults.isSelected()) { 303 new OAuthParameters(null, null, null, null, null, null, null).rememberPreferences(); 304 } else { 305 getAdvancedParameters().rememberPreferences(); 306 } 307 } 308 309 /** 310 * Remembers the current values in the preferences <code>pref</code>. 277 311 * 278 312 * @param pref the preferences. Must not be null. 279 313 * @throws IllegalArgumentException if pref is null. 280 */ 314 * @deprecated (since 12928) replaced by {@link #rememberPreferences()} 315 */ 316 @Deprecated 281 317 public void rememberPreferences(Preferences pref) { 282 318 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); -
trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
r12620 r12928 169 169 /** 170 170 * Initializes the panel with values from the preferences 171 * @param paramApiUrl the API URL 172 */ 173 @Override 174 public void initialize(String paramApiUrl) { 175 super.initialize(paramApiUrl); 176 CredentialsAgent cm = CredentialsManager.getInstance(); 177 try { 178 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER, OsmApi.getOsmApi().getHost()); 179 if (pa == null) { 180 tfUserName.setText(""); 181 tfPassword.setText(""); 182 } else { 183 tfUserName.setText(pa.getUserName() == null ? "" : pa.getUserName()); 184 tfPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword())); 185 } 186 } catch (CredentialsAgentException e) { 187 Logging.error(e); 188 tfUserName.setText(""); 189 tfPassword.setText(""); 190 } 191 } 192 193 /** 194 * Initializes the panel with values from the preferences 171 195 * @param pref Preferences structure 172 */ 196 * @deprecated (since 12928) replaced by {@link #initialize(java.lang.String)} 197 */ 198 @Deprecated 173 199 @Override 174 200 public void initFromPreferences(Preferences pref) { -
trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java
r12803 r12928 40 40 41 41 import org.openstreetmap.josm.Main; 42 import org.openstreetmap.josm.data.Preferences;43 42 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; 44 43 import org.openstreetmap.josm.data.oauth.OAuthParameters; … … 309 308 */ 310 309 public void initFromPreferences() { 311 // Copy current JOSM preferences to update API url with the one used in this wizard 312 Preferences copyPref = new Preferences(Main.pref); 313 copyPref.put("osm-server.url", apiUrl); 314 pnlFullyAutomaticAuthorisationUI.initFromPreferences(copyPref); 315 pnlSemiAutomaticAuthorisationUI.initFromPreferences(copyPref); 316 pnlManualAuthorisationUI.initFromPreferences(copyPref); 310 pnlFullyAutomaticAuthorisationUI.initialize(apiUrl); 311 pnlSemiAutomaticAuthorisationUI.initialize(apiUrl); 312 pnlManualAuthorisationUI.initialize(apiUrl); 317 313 } 318 314 -
trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
r12846 r12928 134 134 135 135 /** 136 * Saves the current values to preferences136 * Saves the current values to the preferences 137 137 */ 138 138 public final void saveToPreferences() { … … 149 149 pnlBasicAuthPreferences.saveToPreferences(); 150 150 OAuthAccessTokenHolder.getInstance().clear(); 151 OAuthAccessTokenHolder.getInstance().save( Main.pref,CredentialsManager.getInstance());151 OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance()); 152 152 } else if ("oauth".equals(authMethod)) { 153 153 // clear the password in the preferences -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
r12686 r12928 96 96 gc.weighty = 1.0; 97 97 pnl.add(pnlAdvancedProperties, gc); 98 pnlAdvancedProperties.init FromPreferences(Main.pref);98 pnlAdvancedProperties.initialize(OsmApi.getOsmApi().getServerUrl()); 99 99 pnlAdvancedProperties.setBorder( 100 100 BorderFactory.createCompoundBorder( … … 162 162 public void saveToPreferences() { 163 163 OAuthAccessTokenHolder.getInstance().setSaveToPreferences(cbSaveToPreferences.isSelected()); 164 OAuthAccessTokenHolder.getInstance().save( Main.pref,CredentialsManager.getInstance());165 pnlAdvancedProperties.rememberPreferences( Main.pref);164 OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance()); 165 pnlAdvancedProperties.rememberPreferences(); 166 166 } 167 167 … … 359 359 public void actionPerformed(ActionEvent evt) { 360 360 OAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken(); 361 OAuthParameters parameters = OAuthParameters.createFrom Preferences(Main.pref);361 OAuthParameters parameters = OAuthParameters.createFromApiUrl(OsmApi.getOsmApi().getServerUrl()); 362 362 TestAccessTokenTask task = new TestAccessTokenTask( 363 363 OAuthAuthenticationPreferencesPanel.this, -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r12869 r12928 114 114 protected void addOAuthAuthorizationHeader(HttpClient connection) throws OsmTransferException { 115 115 if (oauthParameters == null) { 116 oauthParameters = OAuthParameters.createFrom Preferences(Main.pref);116 oauthParameters = OAuthParameters.createFromApiUrl(OsmApi.getOsmApi().getServerUrl()); 117 117 } 118 118 OAuthConsumer consumer = oauthParameters.buildConsumer(); … … 146 146 fetcher.obtainAccessToken(apiUrl); 147 147 OAuthAccessTokenHolder.getInstance().setSaveToPreferences(true); 148 OAuthAccessTokenHolder.getInstance().save( Main.pref,CredentialsManager.getInstance());148 OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance()); 149 149 } catch (MalformedURLException | InterruptedException | InvocationTargetException e) { 150 150 throw new MissingOAuthAccessTokenException(e);
Note:
See TracChangeset
for help on using the changeset viewer.