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

Last change on this file since 12634 was 10831, checked in by Don-vip, 8 years ago

see #13232 - cleanup OAuth signpost code:

  • remove classes unused by JOSM
  • add missing @Override annotations
File size: 1.6 KB
Line 
1package oauth.signpost.signature;
2
3import java.util.Iterator;
4
5import oauth.signpost.OAuth;
6import oauth.signpost.http.HttpParameters;
7import oauth.signpost.http.HttpRequest;
8
9/**
10 * Writes to a URL query string. <strong>Note that this currently ONLY works
11 * when signing a URL directly, not with HTTP request objects.</strong> That's
12 * because most HTTP request implementations do not allow the client to change
13 * the URL once the request has been instantiated, so there is no way to append
14 * parameters to it.
15 *
16 * @author Matthias Kaeppler
17 */
18public class QueryStringSigningStrategy implements SigningStrategy {
19
20 private static final long serialVersionUID = 1L;
21
22 @Override
23 public String writeSignature(String signature, HttpRequest request,
24 HttpParameters requestParameters) {
25
26 // add all (x_)oauth parameters
27 HttpParameters oauthParams = requestParameters.getOAuthParameters();
28 oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);
29
30 Iterator<String> iter = oauthParams.keySet().iterator();
31
32 // add the first query parameter (we always have at least the signature)
33 String firstKey = iter.next();
34 StringBuilder sb = new StringBuilder(OAuth.addQueryString(request.getRequestUrl(),
35 oauthParams.getAsQueryString(firstKey)));
36
37 while (iter.hasNext()) {
38 sb.append("&");
39 String key = iter.next();
40 sb.append(oauthParams.getAsQueryString(key));
41 }
42
43 String signedUrl = sb.toString();
44
45 request.setRequestUrl(signedUrl);
46
47 return signedUrl;
48 }
49
50}
Note: See TracBrowser for help on using the repository browser.