1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.amber.oauth2.client.response;
23
24 import java.util.Map;
25
26 import javax.servlet.http.HttpServletRequest;
27
28 import org.apache.amber.oauth2.client.validator.CodeTokenValidator;
29 import org.apache.amber.oauth2.client.validator.CodeValidator;
30 import org.apache.amber.oauth2.client.validator.OAuthClientValidator;
31 import org.apache.amber.oauth2.client.validator.TokenValidator;
32 import org.apache.amber.oauth2.common.OAuth;
33 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
34 import org.apache.amber.oauth2.common.utils.OAuthUtils;
35
36
37
38
39
40
41
42 public class OAuthAuthzResponse extends OAuthClientResponse {
43
44 private HttpServletRequest request;
45
46 protected OAuthAuthzResponse(HttpServletRequest request, OAuthClientValidator validator) {
47 this.request = request;
48 Map<String, String[]> params = request.getParameterMap();
49 for (Map.Entry<String, String[]> entry : params.entrySet()) {
50 String key = entry.getKey();
51 String[] values = entry.getValue();
52 if (!OAuthUtils.hasEmptyValues(values)) {
53 parameters.put(key, values[0]);
54 }
55 }
56 this.validator = validator;
57 }
58
59 public static OAuthAuthzResponse oauthCodeAuthzResponse(HttpServletRequest request)
60 throws OAuthProblemException {
61 OAuthAuthzResponse response = new OAuthAuthzResponse(request, new CodeValidator());
62 response.validate();
63 return response;
64 }
65
66 public static OAuthAuthzResponse oAuthCodeAndTokenAuthzResponse(HttpServletRequest request)
67 throws OAuthProblemException {
68 OAuthAuthzResponse response = new OAuthAuthzResponse(request, new CodeTokenValidator());
69 response.validate();
70 return response;
71 }
72
73 public static OAuthAuthzResponse oauthTokenAuthzResponse(HttpServletRequest request)
74 throws OAuthProblemException {
75 OAuthAuthzResponse response = new OAuthAuthzResponse(request, new TokenValidator());
76 response.validate();
77 return response;
78 }
79
80 public String getAccessToken() {
81 return getParam(OAuth.OAUTH_ACCESS_TOKEN);
82 }
83
84 public Long getExpiresIn() {
85 String value = getParam(OAuth.OAUTH_EXPIRES_IN);
86 return value == null? null: Long.valueOf(value);
87 }
88
89 public String getScope() {
90 return getParam(OAuth.OAUTH_SCOPE);
91 }
92
93 public String getCode() {
94 return getParam(OAuth.OAUTH_CODE);
95 }
96
97 public String getState() {
98 return getParam(OAuth.OAUTH_STATE);
99 }
100
101 public HttpServletRequest getRequest() {
102 return request;
103 }
104
105 protected void setBody(String body) {
106 this.body = body;
107 }
108
109 protected void setContentType(String contentType) {
110 this.contentType = contentType;
111 }
112
113 protected void setResponseCode(int responseCode) {
114 this.responseCode = responseCode;
115 }
116
117 }