Changeset 10831 in josm
- Timestamp:
- 2016-08-18T00:21:03+02:00 (8 years ago)
- Location:
- trunk/src/oauth/signpost
- Files:
-
- 5 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/oauth/signpost/AbstractOAuthConsumer.java
r6849 r10831 55 55 // these are the params which will be passed to the message signer 56 56 private HttpParameters requestParameters; 57 57 58 58 private boolean sendEmptyTokens; 59 59 60 60 final private Random random = new Random(System.nanoTime()); 61 61 … … 67 67 } 68 68 69 @Override 69 70 public void setMessageSigner(OAuthMessageSigner messageSigner) { 70 71 this.messageSigner = messageSigner; … … 72 73 } 73 74 75 @Override 74 76 public void setSigningStrategy(SigningStrategy signingStrategy) { 75 77 this.signingStrategy = signingStrategy; 76 78 } 77 79 80 @Override 78 81 public void setAdditionalParameters(HttpParameters additionalParameters) { 79 82 this.additionalParameters = additionalParameters; 80 83 } 81 84 85 @Override 82 86 public synchronized HttpRequest sign(HttpRequest request) throws OAuthMessageSignerException, 83 87 OAuthExpectationFailedException, OAuthCommunicationException { … … 116 120 } 117 121 122 @Override 118 123 public synchronized HttpRequest sign(Object request) throws OAuthMessageSignerException, 119 124 OAuthExpectationFailedException, OAuthCommunicationException { … … 121 126 } 122 127 128 @Override 123 129 public synchronized String sign(String url) throws OAuthMessageSignerException, 124 130 OAuthExpectationFailedException, OAuthCommunicationException { … … 147 153 protected abstract HttpRequest wrap(Object request); 148 154 155 @Override 149 156 public void setTokenWithSecret(String token, String tokenSecret) { 150 157 this.token = token; … … 152 159 } 153 160 161 @Override 154 162 public String getToken() { 155 163 return token; 156 164 } 157 165 166 @Override 158 167 public String getTokenSecret() { 159 168 return messageSigner.getTokenSecret(); 160 169 } 161 170 171 @Override 162 172 public String getConsumerKey() { 163 173 return this.consumerKey; 164 174 } 165 175 176 @Override 166 177 public String getConsumerSecret() { 167 178 return this.consumerSecret; … … 207 218 } 208 219 220 @Override 209 221 public HttpParameters getRequestParameters() { 210 222 return requestParameters; 211 223 } 212 224 225 @Override 213 226 public void setSendEmptyTokens(boolean enable) { 214 227 this.sendEmptyTokens = enable; -
trunk/src/oauth/signpost/AbstractOAuthProvider.java
r9227 r10831 59 59 } 60 60 61 @Override 61 62 public synchronized String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl, 62 63 String... customOAuthParams) throws OAuthMessageSignerException, … … 90 91 } 91 92 93 @Override 92 94 public synchronized void retrieveAccessToken(OAuthConsumer consumer, String oauthVerifier, 93 95 String... customOAuthParams) throws OAuthMessageSignerException, … … 291 293 } 292 294 295 @Override 293 296 public HttpParameters getResponseParameters() { 294 297 return responseParameters; … … 308 311 } 309 312 313 @Override 310 314 public void setResponseParameters(HttpParameters parameters) { 311 315 this.responseParameters = parameters; 312 316 } 313 317 318 @Override 314 319 public void setOAuth10a(boolean isOAuth10aProvider) { 315 320 this.isOAuth10a = isOAuth10aProvider; 316 321 } 317 322 323 @Override 318 324 public boolean isOAuth10a() { 319 325 return isOAuth10a; 320 326 } 321 327 328 @Override 322 329 public String getRequestTokenEndpointUrl() { 323 330 return this.requestTokenEndpointUrl; 324 331 } 325 332 333 @Override 326 334 public String getAccessTokenEndpointUrl() { 327 335 return this.accessTokenEndpointUrl; 328 336 } 329 337 338 @Override 330 339 public String getAuthorizationWebsiteUrl() { 331 340 return this.authorizationWebsiteUrl; 332 341 } 333 342 343 @Override 334 344 public void setRequestHeader(String header, String value) { 335 345 defaultHeaders.put(header, value); 336 346 } 337 347 348 @Override 338 349 public Map<String, String> getRequestHeaders() { 339 350 return defaultHeaders; 340 351 } 341 352 353 @Override 342 354 public void setListener(OAuthProviderListener listener) { 343 355 this.listener = listener; 344 356 } 345 357 358 @Override 346 359 public void removeListener(OAuthProviderListener listener) { 347 360 this.listener = null; -
trunk/src/oauth/signpost/OAuthConsumer.java
r6849 r10831 25 25 import oauth.signpost.signature.HmacSha1MessageSigner; 26 26 import oauth.signpost.signature.OAuthMessageSigner; 27 import oauth.signpost.signature.PlainTextMessageSigner;28 27 import oauth.signpost.signature.QueryStringSigningStrategy; 29 28 import oauth.signpost.signature.SigningStrategy; … … 38 37 * HTTP messages are signed as follows: 39 38 * <p> 40 * 39 * 41 40 * <pre> 42 41 * // exchange the arguments with the actual token/secret pair 43 42 * OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678"); 44 * 43 * 45 44 * URL url = new URL("http://example.com/protected.xml"); 46 45 * HttpURLConnection request = (HttpURLConnection) url.openConnection(); 47 * 46 * 48 47 * consumer.sign(request); 49 * 48 * 50 49 * request.connect(); 51 50 * </pre> 52 * 51 * 53 52 * </p> 54 53 * </p> 55 * 54 * 56 55 * @author Matthias Kaeppler 57 56 */ … … 61 60 * Sets the message signer that should be used to generate the OAuth 62 61 * signature. 63 * 62 * 64 63 * @param messageSigner 65 64 * the signer 66 65 * @see HmacSha1MessageSigner 67 * @see PlainTextMessageSigner68 66 */ 69 67 public void setMessageSigner(OAuthMessageSigner messageSigner); … … 79 77 * as-is. <b>BE CAREFUL WITH THIS METHOD! Your service provider may decide 80 78 * to ignore any non-standard OAuth params when computing the signature.</b> 81 * 79 * 82 80 * @param additionalParameters 83 81 * the parameters … … 88 86 * Defines which strategy should be used to write a signature to an HTTP 89 87 * request. 90 * 88 * 91 89 * @param signingStrategy 92 90 * the strategy … … 102 100 * {@link OAuthProvider#retrieveRequestToken}, try setting this to true. 103 101 * </p> 104 * 102 * 105 103 * @param enable 106 104 * true or false … … 112 110 * required OAuth parameters) to it. Where these parameters are written 113 111 * depends on the current {@link SigningStrategy}. 114 * 112 * 115 113 * @param request 116 114 * the request to sign … … 132 130 * implementation must ensure that only those request types are passed which 133 131 * it supports. 134 * 132 * 135 133 * @param request 136 134 * the request to sign … … 152 150 * request that is being sent. 153 151 * </p> 154 * 152 * 155 153 * @param url 156 154 * the input URL. May have query parameters. … … 166 164 /** 167 165 * Sets the OAuth token and token secret used for message signing. 168 * 166 * 169 167 * @param token 170 168 * the token … … 189 187 * is the exact set of parameters that were used for creating the message 190 188 * signature. 191 * 189 * 192 190 * @return the request parameters used for message signing 193 191 */ -
trunk/src/oauth/signpost/OAuthProvider.java
r6849 r10831 14 14 import java.util.Map; 15 15 16 import oauth.signpost.basic.DefaultOAuthConsumer;17 import oauth.signpost.basic.DefaultOAuthProvider;18 16 import oauth.signpost.exception.OAuthCommunicationException; 19 17 import oauth.signpost.exception.OAuthExpectationFailedException; … … 35 33 * resource authorization, e.g.: 36 34 * </p> 37 * 35 * 38 36 * <pre> 39 37 * OAuthProvider provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token", … … 49 47 * </p> 50 48 * <p> 51 * 49 * 52 50 * <pre> 53 51 * String url = provider.retrieveRequestToken(consumer, "http://www.example.com/callback"); 54 52 * </pre> 55 * 53 * 56 54 * </p> 57 55 * <p> … … 64 62 * </p> 65 63 * <p> 66 * 64 * 67 65 * <pre> 68 66 * provider.retrieveAccessToken(consumer, nullOrVerifierCode); 69 67 * </pre> 70 * 68 * 71 69 * </p> 72 70 * <p> … … 78 76 * The consumer used during token handshakes is now ready for signing. 79 77 * </p> 80 * 81 * @see DefaultOAuthProvider 82 * @see DefaultOAuthConsumer 78 * 83 79 * @see OAuthProviderListener 84 80 */ … … 95 91 * unauthorized request token and token secret set. 96 92 * </p> 97 * 93 * 98 94 * @param consumer 99 95 * the {@link OAuthConsumer} that should be used to sign the request … … 143 139 * access token and token secret set. 144 140 * </p> 145 * 141 * 146 142 * @param consumer 147 143 * the {@link OAuthConsumer} that should be used to sign the request … … 187 183 * parameters contained in the server response. It's the caller's 188 184 * responsibility that any OAuth parameters be removed beforehand. 189 * 185 * 190 186 * @param parameters 191 187 * the map of query parameters served by the service provider in the … … 198 194 * which are sent to retrieve tokens. @deprecated THIS METHOD HAS BEEN 199 195 * DEPRECATED. Use {@link OAuthProviderListener} to customize requests. 200 * 196 * 201 197 * @param header 202 198 * The header name (e.g. 'WWW-Authenticate') -
trunk/src/oauth/signpost/basic/UrlStringRequestAdapter.java
r4231 r10831 16 16 } 17 17 18 @Override 18 19 public String getMethod() { 19 20 return "GET"; 20 21 } 21 22 23 @Override 22 24 public String getRequestUrl() { 23 25 return url; 24 26 } 25 27 28 @Override 26 29 public void setRequestUrl(String url) { 27 30 this.url = url; 28 31 } 29 32 33 @Override 30 34 public void setHeader(String name, String value) { 31 35 } 32 36 37 @Override 33 38 public String getHeader(String name) { 34 39 return null; 35 40 } 36 41 42 @Override 37 43 public Map<String, String> getAllHeaders() { 38 44 return Collections.emptyMap(); 39 45 } 40 46 47 @Override 41 48 public InputStream getMessagePayload() throws IOException { 42 49 return null; 43 50 } 44 51 52 @Override 45 53 public String getContentType() { 46 54 return null; 47 55 } 48 56 57 @Override 49 58 public Object unwrap() { 50 59 return url; -
trunk/src/oauth/signpost/http/HttpParameters.java
r6849 r10831 30 30 * A multi-map of HTTP request parameters. Each key references a 31 31 * {@link SortedSet} of parameters collected from the request during message 32 * signing. Parameter values are sorted as per {@linkplain http 33 * ://oauth.net/core/1.0a/#anchor13}. Every key/value pair will be 34 * percent-encoded upon insertion. This class has special semantics tailored to 35 * being useful for message signing; it's not a general purpose collection class 36 * to handle request parameters. 37 * 32 * signing. Parameter values are sorted as per {@linkplain http://oauth.net/core/1.0a/#anchor13}. 33 * Every key/value pair will be percent-encoded upon insertion. 34 * This class has special semantics tailored to being useful for message signing; 35 * it's not a general purpose collection class to handle request parameters. 36 * 38 37 * @author Matthias Kaeppler 39 38 */ … … 41 40 public class HttpParameters implements Map<String, SortedSet<String>>, Serializable { 42 41 43 private TreeMap<String, SortedSet<String>> wrappedMap = new TreeMap<String, SortedSet<String>>(); 44 42 private TreeMap<String, SortedSet<String>> wrappedMap = new TreeMap<>(); 43 44 @Override 45 45 public SortedSet<String> put(String key, SortedSet<String> value) { 46 46 return wrappedMap.put(key, value); … … 62 62 * Convenience method to add a single value for the parameter specified by 63 63 * 'key'. 64 * 64 * 65 65 * @param key 66 66 * the parameter name … … 76 76 * Convenience method to add a single value for the parameter specified by 77 77 * 'key'. 78 * 78 * 79 79 * @param key 80 80 * the parameter name … … 91 91 SortedSet<String> values = wrappedMap.get(key); 92 92 if (values == null) { 93 values = new TreeSet< String>();93 values = new TreeSet<>(); 94 94 wrappedMap.put( key, values); 95 95 } … … 105 105 * Convenience method to allow for storing null values. {@link #put} doesn't 106 106 * allow null values, because that would be ambiguous. 107 * 107 * 108 108 * @param key 109 109 * the parameter name … … 116 116 } 117 117 118 @Override 118 119 public void putAll(Map<? extends String, ? extends SortedSet<String>> m) { 119 120 wrappedMap.putAll(m); … … 138 139 /** 139 140 * Convenience method to merge a Map<String, List<String>>. 140 * 141 * 141 142 * @param m 142 143 * the map … … 146 147 SortedSet<String> vals = get(key); 147 148 if (vals == null) { 148 vals = new TreeSet< String>();149 vals = new TreeSet<>(); 149 150 put(key, vals); 150 151 } … … 153 154 } 154 155 156 @Override 155 157 public SortedSet<String> get(Object key) { 156 158 return wrappedMap.get(key); … … 159 161 /** 160 162 * Convenience method for {@link #getFirst(key, false)}. 161 * 163 * 162 164 * @param key 163 165 * the parameter name (must be percent encoded if it contains unsafe … … 176 178 * (that's because upon storing values in this map, keys get 177 179 * percent-encoded). 178 * 180 * 179 181 * @param key 180 182 * the parameter name (must be percent encoded if it contains unsafe … … 196 198 * Concatenates all values for the given key to a list of key/value pairs 197 199 * suitable for use in a URL query string. 198 * 200 * 199 201 * @param key 200 202 * the parameter name … … 208 210 * Concatenates all values for the given key to a list of key/value pairs 209 211 * suitable for use in a URL query string. 210 * 212 * 211 213 * @param key 212 214 * the parameter name … … 237 239 return sb.toString(); 238 240 } 239 241 240 242 public String getAsHeaderElement(String key) { 241 243 String value = getFirst(key); … … 246 248 } 247 249 250 @Override 248 251 public boolean containsKey(Object key) { 249 252 return wrappedMap.containsKey(key); 250 253 } 251 254 255 @Override 252 256 public boolean containsValue(Object value) { 253 257 for (Set<String> values : wrappedMap.values()) { … … 259 263 } 260 264 265 @Override 261 266 public int size() { 262 267 int count = 0; … … 267 272 } 268 273 274 @Override 269 275 public boolean isEmpty() { 270 276 return wrappedMap.isEmpty(); 271 277 } 272 278 279 @Override 273 280 public void clear() { 274 281 wrappedMap.clear(); 275 282 } 276 283 284 @Override 277 285 public SortedSet<String> remove(Object key) { 278 286 return wrappedMap.remove(key); 279 287 } 280 288 289 @Override 281 290 public Set<String> keySet() { 282 291 return wrappedMap.keySet(); 283 292 } 284 293 294 @Override 285 295 public Collection<SortedSet<String>> values() { 286 296 return wrappedMap.values(); 287 297 } 288 298 299 @Override 289 300 public Set<Entry<String, SortedSet<String>>> entrySet() { 290 301 return wrappedMap.entrySet(); -
trunk/src/oauth/signpost/http/HttpRequest.java
r4231 r10831 6 6 7 7 import oauth.signpost.OAuthConsumer; 8 import oauth.signpost.basic.HttpURLConnectionRequestAdapter;9 8 10 9 /** … … 14 13 * currently supported, you'll have to write an adapter which implements this 15 14 * interface and a custom {@link OAuthConsumer} which performs the wrapping. 16 * 17 * @see HttpURLConnectionRequestAdapter 15 * 18 16 * @author Matthias Kaeppler 19 17 */ … … 38 36 /** 39 37 * Returns the wrapped request object, in case you must work directly on it. 40 * 38 * 41 39 * @return the wrapped request object 42 40 */ -
trunk/src/oauth/signpost/signature/AuthorizationHeaderSigningStrategy.java
r6849 r10831 9 9 /** 10 10 * Writes to the HTTP Authorization header field. 11 * 11 * 12 12 * @author Matthias Kaeppler 13 13 */ … … 16 16 private static final long serialVersionUID = 1L; 17 17 18 @Override 18 19 public String writeSignature(String signature, HttpRequest request, 19 20 HttpParameters requestParameters) { -
trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java
r6849 r10831 13 13 * the URL once the request has been instantiated, so there is no way to append 14 14 * parameters to it. 15 * 15 * 16 16 * @author Matthias Kaeppler 17 17 */ … … 20 20 private static final long serialVersionUID = 1L; 21 21 22 @Override 22 23 public String writeSignature(String signature, HttpRequest request, 23 24 HttpParameters requestParameters) {
Note:
See TracChangeset
for help on using the changeset viewer.