- Timestamp:
- 2015-12-30T03:21:52+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java
r9172 r9220 14 14 15 15 /** 16 * This class manages a set of OAuth parameters.16 * This class manages an immutable set of OAuth parameters. 17 17 * @since 2747 18 18 */ … … 40 40 public static final String DEFAULT_AUTHORISE_URL = Main.getOSMWebsite() + "/oauth/authorize"; 41 41 42 43 42 /** 44 43 * Replies a set of default parameters for a consumer accessing the standard OSM server … … 61 60 */ 62 61 public static OAuthParameters createDefault(String apiUrl) { 63 OAuthParameters parameters = new OAuthParameters(); 64 parameters.setConsumerKey(DEFAULT_JOSM_CONSUMER_KEY); 65 parameters.setConsumerSecret(DEFAULT_JOSM_CONSUMER_SECRET); 66 parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL); 67 parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL); 68 parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL); 62 String host = ""; 69 63 if (!OsmApi.DEFAULT_API_URL.equals(apiUrl)) { 70 64 try { 71 String host = new URL(apiUrl).getHost(); 72 if (host.endsWith("dev.openstreetmap.org")) { 73 parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL.replace("www.openstreetmap.org", host)); 74 parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL.replace("www.openstreetmap.org", host)); 75 parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL.replace("www.openstreetmap.org", host)); 76 } 65 host = new URL(apiUrl).getHost(); 77 66 } catch (MalformedURLException e) { 78 67 // Ignored … … 82 71 } 83 72 } 84 return parameters; 73 boolean osmDevServer = host.endsWith("dev.openstreetmap.org"); 74 return new OAuthParameters( 75 DEFAULT_JOSM_CONSUMER_KEY, 76 DEFAULT_JOSM_CONSUMER_SECRET, 77 osmDevServer ? DEFAULT_REQUEST_TOKEN_URL.replace("www.openstreetmap.org", host) : DEFAULT_REQUEST_TOKEN_URL, 78 osmDevServer ? DEFAULT_ACCESS_TOKEN_URL.replace("www.openstreetmap.org", host) : DEFAULT_ACCESS_TOKEN_URL, 79 osmDevServer ? DEFAULT_AUTHORISE_URL.replace("www.openstreetmap.org", host) : DEFAULT_AUTHORISE_URL); 85 80 } 86 81 … … 93 88 public static OAuthParameters createFromPreferences(Preferences pref) { 94 89 OAuthParameters parameters = createDefault(pref.get("osm-server.url")); 95 parameters.setConsumerKey(pref.get("oauth.settings.consumer-key", parameters.getConsumerKey())); 96 parameters.setConsumerSecret(pref.get("oauth.settings.consumer-secret", parameters.getConsumerSecret())); 97 parameters.setRequestTokenUrl(pref.get("oauth.settings.request-token-url", parameters.getRequestTokenUrl())); 98 parameters.setAccessTokenUrl(pref.get("oauth.settings.access-token-url", parameters.getAccessTokenUrl())); 99 parameters.setAuthoriseUrl(pref.get("oauth.settings.authorise-url", parameters.getAuthoriseUrl())); 100 return parameters; 101 } 102 103 private String consumerKey; 104 private String consumerSecret; 105 private String requestTokenUrl; 106 private String accessTokenUrl; 107 private String authoriseUrl; 108 109 /** 110 * Constructs a new, unitialized, {@code OAuthParameters}. 90 return new OAuthParameters( 91 pref.get("oauth.settings.consumer-key", parameters.getConsumerKey()), 92 pref.get("oauth.settings.consumer-secret", parameters.getConsumerSecret()), 93 pref.get("oauth.settings.request-token-url", parameters.getRequestTokenUrl()), 94 pref.get("oauth.settings.access-token-url", parameters.getAccessTokenUrl()), 95 pref.get("oauth.settings.authorise-url", parameters.getAuthoriseUrl()) 96 ); 97 } 98 99 private final String consumerKey; 100 private final String consumerSecret; 101 private final String requestTokenUrl; 102 private final String accessTokenUrl; 103 private final String authoriseUrl; 104 105 /** 106 * Constructs a new {@code OAuthParameters}. 107 * @param consumerKey consumer key 108 * @param consumerSecret consumer secret 109 * @param requestTokenUrl request token URL 110 * @param accessTokenUrl access token URL 111 * @param authoriseUrl authorise URL 111 112 * 112 113 * @see #createDefault 113 114 * @see #createFromPreferences 114 */ 115 public OAuthParameters() { 116 // contents can be set later with setters 115 * @since 9220 116 */ 117 public OAuthParameters(String consumerKey, String consumerSecret, 118 String requestTokenUrl, String accessTokenUrl, String authoriseUrl) { 119 this.consumerKey = consumerKey; 120 this.consumerSecret = consumerSecret; 121 this.requestTokenUrl = requestTokenUrl; 122 this.accessTokenUrl = accessTokenUrl; 123 this.authoriseUrl = authoriseUrl; 117 124 } 118 125 … … 141 148 142 149 /** 143 * Sets the consumer key.144 * @param consumerKey The consumer key145 */146 public void setConsumerKey(String consumerKey) {147 this.consumerKey = consumerKey;148 }149 150 /**151 150 * Gets the consumer secret. 152 151 * @return The consumer secret … … 157 156 158 157 /** 159 * Sets the consumer secret.160 * @param consumerSecret The consumer secret161 */162 public void setConsumerSecret(String consumerSecret) {163 this.consumerSecret = consumerSecret;164 }165 166 /**167 158 * Gets the request token URL. 168 159 * @return The request token URL … … 173 164 174 165 /** 175 * Sets the request token URL.176 * @param requestTokenUrl the request token URL177 */178 public void setRequestTokenUrl(String requestTokenUrl) {179 this.requestTokenUrl = requestTokenUrl;180 }181 182 /**183 166 * Gets the access token URL. 184 167 * @return The access token URL … … 189 172 190 173 /** 191 * Sets the access token URL.192 * @param accessTokenUrl The access token URL193 */194 public void setAccessTokenUrl(String accessTokenUrl) {195 this.accessTokenUrl = accessTokenUrl;196 }197 198 /**199 174 * Gets the authorise URL. 200 175 * @return The authorise URL … … 202 177 public String getAuthoriseUrl() { 203 178 return authoriseUrl; 204 }205 206 /**207 * Sets the authorise URL.208 * @param authoriseUrl The authorise URL209 */210 public void setAuthoriseUrl(String authoriseUrl) {211 this.authoriseUrl = authoriseUrl;212 179 } 213 180 -
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r9075 r9220 193 193 if (cbUseDefaults.isSelected()) 194 194 return OAuthParameters.createDefault(apiUrl); 195 OAuthParameters parameters = new OAuthParameters(); 196 parameters.setConsumerKey(tfConsumerKey.getText()); 197 parameters.setConsumerSecret(tfConsumerSecret.getText()); 198 parameters.setRequestTokenUrl(tfRequestTokenURL.getText()); 199 parameters.setAccessTokenUrl(tfAccessTokenURL.getText()); 200 parameters.setAuthoriseUrl(tfAuthoriseURL.getText()); 201 return parameters; 195 return new OAuthParameters( 196 tfConsumerKey.getText(), 197 tfConsumerSecret.getText(), 198 tfRequestTokenURL.getText(), 199 tfAccessTokenURL.getText(), 200 tfAuthoriseURL.getText()); 202 201 } 203 202
Note:
See TracChangeset
for help on using the changeset viewer.