1 | package oauth.signpost.signature;
|
---|
2 |
|
---|
3 | import oauth.signpost.OAuth;
|
---|
4 | import oauth.signpost.http.HttpParameters;
|
---|
5 | import oauth.signpost.http.HttpRequest;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Writes to the HTTP Authorization header field.
|
---|
9 | *
|
---|
10 | * @author Matthias Kaeppler
|
---|
11 | */
|
---|
12 | public class AuthorizationHeaderSigningStrategy implements SigningStrategy {
|
---|
13 |
|
---|
14 | private static final long serialVersionUID = 1L;
|
---|
15 |
|
---|
16 | public String writeSignature(String signature, HttpRequest request,
|
---|
17 | HttpParameters requestParameters) {
|
---|
18 | StringBuilder sb = new StringBuilder();
|
---|
19 |
|
---|
20 | sb.append("OAuth ");
|
---|
21 | if (requestParameters.containsKey("realm")) {
|
---|
22 | sb.append(requestParameters.getAsHeaderElement("realm"));
|
---|
23 | sb.append(", ");
|
---|
24 | }
|
---|
25 | if (requestParameters.containsKey(OAuth.OAUTH_TOKEN)) {
|
---|
26 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_TOKEN));
|
---|
27 | sb.append(", ");
|
---|
28 | }
|
---|
29 | if (requestParameters.containsKey(OAuth.OAUTH_CALLBACK)) {
|
---|
30 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_CALLBACK));
|
---|
31 | sb.append(", ");
|
---|
32 | }
|
---|
33 | if (requestParameters.containsKey(OAuth.OAUTH_VERIFIER)) {
|
---|
34 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_VERIFIER));
|
---|
35 | sb.append(", ");
|
---|
36 | }
|
---|
37 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_CONSUMER_KEY));
|
---|
38 | sb.append(", ");
|
---|
39 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_VERSION));
|
---|
40 | sb.append(", ");
|
---|
41 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_SIGNATURE_METHOD));
|
---|
42 | sb.append(", ");
|
---|
43 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_TIMESTAMP));
|
---|
44 | sb.append(", ");
|
---|
45 | sb.append(requestParameters.getAsHeaderElement(OAuth.OAUTH_NONCE));
|
---|
46 | sb.append(", ");
|
---|
47 | sb.append(OAuth.toHeaderElement(OAuth.OAUTH_SIGNATURE, signature));
|
---|
48 |
|
---|
49 | String header = sb.toString();
|
---|
50 | request.setHeader(OAuth.HTTP_AUTHORIZATION_HEADER, header);
|
---|
51 |
|
---|
52 | return header;
|
---|
53 | }
|
---|
54 |
|
---|
55 | }
|
---|