source: josm/trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java@ 5693

Last change on this file since 5693 was 4231, checked in by stoecker, 13 years ago

add signpost and metadata extractor code to repository directly

File size: 2.2 KB
Line 
1package oauth.signpost.signature;
2
3import oauth.signpost.OAuth;
4import oauth.signpost.http.HttpParameters;
5import oauth.signpost.http.HttpRequest;
6
7/**
8 * Writes to a URL query string. <strong>Note that this currently ONLY works
9 * when signing a URL directly, not with HTTP request objects.</strong> That's
10 * because most HTTP request implementations do not allow the client to change
11 * the URL once the request has been instantiated, so there is no way to append
12 * parameters to it.
13 *
14 * @author Matthias Kaeppler
15 */
16public class QueryStringSigningStrategy implements SigningStrategy {
17
18 private static final long serialVersionUID = 1L;
19
20 public String writeSignature(String signature, HttpRequest request,
21 HttpParameters requestParameters) {
22
23 // add the signature
24 StringBuilder sb = new StringBuilder(OAuth.addQueryParameters(request.getRequestUrl(),
25 OAuth.OAUTH_SIGNATURE, signature));
26
27 // add the optional OAuth parameters
28 if (requestParameters.containsKey(OAuth.OAUTH_TOKEN)) {
29 sb.append("&");
30 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_TOKEN));
31 }
32 if (requestParameters.containsKey(OAuth.OAUTH_CALLBACK)) {
33 sb.append("&");
34 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_CALLBACK));
35 }
36 if (requestParameters.containsKey(OAuth.OAUTH_VERIFIER)) {
37 sb.append("&");
38 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_VERIFIER));
39 }
40
41 // add the remaining OAuth params
42 sb.append("&");
43 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_CONSUMER_KEY));
44 sb.append("&");
45 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_VERSION));
46 sb.append("&");
47 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_SIGNATURE_METHOD));
48 sb.append("&");
49 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_TIMESTAMP));
50 sb.append("&");
51 sb.append(requestParameters.getAsQueryString(OAuth.OAUTH_NONCE));
52
53 String signedUrl = sb.toString();
54
55 request.setRequestUrl(signedUrl);
56
57 return signedUrl;
58 }
59
60}
Note: See TracBrowser for help on using the repository browser.