Changeset 9355 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2016-01-09T18:07:26+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/oauth
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r9220 r9355 35 35 * <li>Access token URL</li> 36 36 * <li>Authorize URL</li> 37 * <li>OSM login URL</li> 38 * <li>OSM logout URL</li> 37 39 * </ul> 38 40 * … … 48 50 private JosmTextField tfAccessTokenURL; 49 51 private JosmTextField tfAuthoriseURL; 52 private JosmTextField tfOsmLoginURL; 53 private JosmTextField tfOsmLogoutURL; 50 54 private transient UseDefaultItemListener ilUseDefault; 51 55 private String apiUrl; … … 120 124 SelectAllOnFocusGainedDecorator.decorate(tfAuthoriseURL); 121 125 126 127 // -- OSM login URL 128 gc.gridy = 6; 129 gc.gridx = 0; 130 gc.weightx = 0.0; 131 add(new JLabel(tr("OSM login URL:")), gc); 132 133 gc.gridx = 1; 134 gc.weightx = 1.0; 135 add(tfOsmLoginURL = new JosmTextField(), gc); 136 SelectAllOnFocusGainedDecorator.decorate(tfOsmLoginURL); 137 138 139 // -- OSM logout URL 140 gc.gridy = 7; 141 gc.gridx = 0; 142 gc.weightx = 0.0; 143 add(new JLabel(tr("OSM logout URL:")), gc); 144 145 gc.gridx = 1; 146 gc.weightx = 1.0; 147 add(tfOsmLogoutURL = new JosmTextField(), gc); 148 SelectAllOnFocusGainedDecorator.decorate(tfOsmLogoutURL); 149 122 150 cbUseDefaults.addItemListener(ilUseDefault = new UseDefaultItemListener()); 123 151 } … … 125 153 protected boolean hasCustomSettings() { 126 154 OAuthParameters params = OAuthParameters.createDefault(apiUrl); 127 return 128 !tfConsumerKey.getText().equals(params.getConsumerKey()) 129 || !tfConsumerSecret.getText().equals(params.getConsumerSecret()) 130 || !tfRequestTokenURL.getText().equals(params.getRequestTokenUrl()) 131 || !tfAccessTokenURL.getText().equals(params.getAccessTokenUrl()) 132 || !tfAuthoriseURL.getText().equals(params.getAuthoriseUrl()); 155 return !params.equals(getAdvancedParameters()); 133 156 } 134 157 … … 173 196 tfAccessTokenURL.setText(params.getAccessTokenUrl()); 174 197 tfAuthoriseURL.setText(params.getAuthoriseUrl()); 198 tfOsmLoginURL.setText(params.getOsmLoginUrl()); 199 tfOsmLogoutURL.setText(params.getOsmLogoutUrl()); 175 200 176 201 setChildComponentsEnabled(false); … … 198 223 tfRequestTokenURL.getText(), 199 224 tfAccessTokenURL.getText(), 200 tfAuthoriseURL.getText()); 225 tfAuthoriseURL.getText(), 226 tfOsmLoginURL.getText(), 227 tfOsmLogoutURL.getText()); 201 228 } 202 229 … … 220 247 tfAccessTokenURL.setText(parameters.getAccessTokenUrl() == null ? "" : parameters.getAccessTokenUrl()); 221 248 tfAuthoriseURL.setText(parameters.getAuthoriseUrl() == null ? "" : parameters.getAuthoriseUrl()); 249 tfOsmLoginURL.setText(parameters.getOsmLoginUrl() == null ? "" : parameters.getOsmLoginUrl()); 250 tfOsmLogoutURL.setText(parameters.getOsmLogoutUrl() == null ? "" : parameters.getOsmLogoutUrl()); 222 251 } 223 252 } … … 244 273 resetToDefaultSettings(); 245 274 } else { 246 cbUseDefaults.setSelected(false); 247 tfConsumerKey.setText(pref.get("oauth.settings.consumer-key", OAuthParameters.DEFAULT_JOSM_CONSUMER_KEY)); 248 tfConsumerSecret.setText(pref.get("oauth.settings.consumer-secret", OAuthParameters.DEFAULT_JOSM_CONSUMER_SECRET)); 249 tfRequestTokenURL.setText(pref.get("oauth.settings.request-token-url", OAuthParameters.DEFAULT_REQUEST_TOKEN_URL)); 250 tfAccessTokenURL.setText(pref.get("oauth.settings.access-token-url", OAuthParameters.DEFAULT_ACCESS_TOKEN_URL)); 251 tfAuthoriseURL.setText(pref.get("oauth.settings.authorise-url", OAuthParameters.DEFAULT_AUTHORISE_URL)); 252 setChildComponentsEnabled(true); 275 setAdvancedParameters(OAuthParameters.createFromPreferences(pref)); 253 276 } 254 277 ilUseDefault.setEnabled(true); … … 265 288 pref.put("oauth.settings.use-default", cbUseDefaults.isSelected()); 266 289 if (cbUseDefaults.isSelected()) { 267 pref.put("oauth.settings.consumer-key", null); 268 pref.put("oauth.settings.consumer-secret", null); 269 pref.put("oauth.settings.request-token-url", null); 270 pref.put("oauth.settings.access-token-url", null); 271 pref.put("oauth.settings.authorise-url", null); 290 new OAuthParameters(null, null, null, null, null, null, null).rememberPreferences(pref); 272 291 } else { 273 pref.put("oauth.settings.consumer-key", tfConsumerKey.getText().trim()); 274 pref.put("oauth.settings.consumer-secret", tfConsumerSecret.getText().trim()); 275 pref.put("oauth.settings.request-token-url", tfRequestTokenURL.getText().trim()); 276 pref.put("oauth.settings.access-token-url", tfAccessTokenURL.getText().trim()); 277 pref.put("oauth.settings.authorise-url", tfAuthoriseURL.getText().trim()); 292 getAdvancedParameters().rememberPreferences(pref); 278 293 } 279 294 } -
trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
r9352 r9355 479 479 480 480 protected void alertLoginFailed(OsmLoginFailedException e) { 481 String loginUrl = null; 482 try { 483 loginUrl = authClient.buildOsmLoginUrl(); 484 } catch (OsmOAuthAuthorizationException e1) { 485 alertInvalidLoginUrl(); 486 return; 487 } 481 final String loginUrl = getAdvancedPropertiesPanel().getAdvancedParameters().getOsmLoginUrl(); 488 482 HelpAwareOptionPane.showOptionDialog( 489 483 FullyAutomaticAuthorizationUI.this, -
trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java
r9309 r9355 8 8 import java.lang.reflect.Field; 9 9 import java.net.HttpURLConnection; 10 import java.net.MalformedURLException;11 10 import java.net.URL; 12 11 import java.nio.charset.StandardCharsets; … … 247 246 248 247 /** 249 * Derives the OSM login URL from the OAuth Authorization Website URL250 *251 * @return the OSM login URL252 * @throws OsmOAuthAuthorizationException if something went wrong, in particular if the253 * URLs are malformed254 */255 public String buildOsmLoginUrl() throws OsmOAuthAuthorizationException {256 try {257 URL autUrl = new URL(oauthProviderParameters.getAuthoriseUrl());258 URL url = new URL(Main.pref.get("oauth.protocol", "https"), autUrl.getHost(), autUrl.getPort(), "/login");259 return url.toString();260 } catch (MalformedURLException e) {261 throw new OsmOAuthAuthorizationException(e);262 }263 }264 265 /**266 * Derives the OSM logout URL from the OAuth Authorization Website URL267 *268 * @return the OSM logout URL269 * @throws OsmOAuthAuthorizationException if something went wrong, in particular if the270 * URLs are malformed271 */272 protected String buildOsmLogoutUrl() throws OsmOAuthAuthorizationException {273 try {274 URL autUrl = new URL(oauthProviderParameters.getAuthoriseUrl());275 URL url = new URL(Main.pref.get("oauth.protocol", "https"), autUrl.getHost(), autUrl.getPort(), "/logout");276 return url.toString();277 } catch (MalformedURLException e) {278 throw new OsmOAuthAuthorizationException(e);279 }280 }281 282 /**283 248 * Submits a request to the OSM website for a login form. The OSM website replies a session ID in 284 249 * a cookie. … … 289 254 protected SessionId fetchOsmWebsiteSessionId() throws OsmOAuthAuthorizationException { 290 255 try { 291 StringBuilder sb = new StringBuilder(); 292 sb.append(buildOsmLoginUrl()).append("?cookie_test=true"); 293 URL url = new URL(sb.toString()); 256 final URL url = new URL(oauthProviderParameters.getOsmLoginUrl() + "?cookie_test=true"); 294 257 synchronized (this) { 295 258 connection = HttpClient.create(url); … … 341 304 protected void authenticateOsmSession(SessionId sessionId, String userName, String password) throws OsmLoginFailedException { 342 305 try { 343 URL url = new URL(buildOsmLoginUrl());306 final URL url = new URL(oauthProviderParameters.getOsmLoginUrl()); 344 307 final HttpClient client = HttpClient.create(url, "POST").useCache(false); 345 308 … … 383 346 protected void logoutOsmSession(SessionId sessionId) throws OsmOAuthAuthorizationException { 384 347 try { 385 URL url = new URL( buildOsmLogoutUrl());348 URL url = new URL(oauthProviderParameters.getOsmLogoutUrl()); 386 349 synchronized (this) { 387 350 connection = HttpClient.create(url).setMaxRedirects(-1);
Note:
See TracChangeset
for help on using the changeset viewer.