gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.xdi.oxauth.model.uma.TTokenRequest クラス
org.xdi.oxauth.model.uma.TTokenRequest 連携図
Collaboration graph

公開メンバ関数

 TTokenRequest (URI baseUri)
 
Token pat (final String authorizePath, final String tokenPath, final String userId, final String userSecret, final String umaClientId, final String umaClientSecret, final String umaRedirectUri)
 
Token newTokenByRefreshToken (final String tokenPath, final Token p_oldToken, final String umaClientId, final String umaClientSecret)
 
RPTResponse requestRpt (final String p_rptPath)
 
RptIntrospectionResponse requestRptStatus (String p_umaRptStatusPath, final String rpt)
 

非公開メンバ関数

Token internalRequest (final String authorizePath, final String tokenPath, final String userId, final String userSecret, final String umaClientId, final String umaClientSecret, final String umaRedirectUri, final UmaScopeType p_scopeType)
 
void requestAuthorizationCode (final String authorizePath, final String userId, final String userSecret, final String umaClientId, final String umaRedirectUri, final UmaScopeType p_scopeType) throws Exception
 
void requestAuthorizationCode (final String authorizePath, final String userId, final String userSecret, final String umaClientId, final String umaRedirectUri, final String p_scopeType) throws Exception
 
void requestToken (final String tokenPath, final String umaClientId, final String umaClientSecret, final String umaRedirectUri) throws Exception
 

非公開変数類

final URI baseUri
 
final Token token = new Token()
 

詳解

著者
Yuriy Zabrovarnyy
バージョン
June 23, 2015

構築子と解体子

◆ TTokenRequest()

org.xdi.oxauth.model.uma.TTokenRequest.TTokenRequest ( URI  baseUri)
inline
56  {
57  assertNotNull(baseUri); // must not be null
58  this.baseUri = baseUri;
59  }
final URI baseUri
Definition: TTokenRequest.java:53

関数詳解

◆ internalRequest()

Token org.xdi.oxauth.model.uma.TTokenRequest.internalRequest ( final String  authorizePath,
final String  tokenPath,
final String  userId,
final String  userSecret,
final String  umaClientId,
final String  umaClientSecret,
final String  umaRedirectUri,
final UmaScopeType  p_scopeType 
)
inlineprivate
125  {
126  try {
127  requestAuthorizationCode(authorizePath, userId, userSecret, umaClientId, umaRedirectUri, p_scopeType);
128  requestToken(tokenPath, umaClientId, umaClientSecret, umaRedirectUri);
129 
130  } catch (Exception e) {
131  e.printStackTrace();
132  fail(e.getMessage());
133  }
134 
135  UmaTestUtil.assert_(token);
136  return token;
137  }
void requestAuthorizationCode(final String authorizePath, final String userId, final String userSecret, final String umaClientId, final String umaRedirectUri, final UmaScopeType p_scopeType)
Definition: TTokenRequest.java:139
final Token token
Definition: TTokenRequest.java:54
void requestToken(final String tokenPath, final String umaClientId, final String umaClientSecret, final String umaRedirectUri)
Definition: TTokenRequest.java:206

◆ newTokenByRefreshToken()

Token org.xdi.oxauth.model.uma.TTokenRequest.newTokenByRefreshToken ( final String  tokenPath,
final Token  p_oldToken,
final String  umaClientId,
final String  umaClientSecret 
)
inline
68  {
69  if (p_oldToken == null || StringUtils.isBlank(p_oldToken.getRefreshToken()) || StringUtils.isBlank(tokenPath)) {
70  throw new IllegalArgumentException("Refresh token or tokenPath is empty.");
71  }
72 
73  final Holder<Token> t = new Holder<Token>();
74  try {
75  TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
76  tokenRequest.setAuthUsername(umaClientId);
77  tokenRequest.setAuthPassword(umaClientSecret);
78  tokenRequest.setRefreshToken(p_oldToken.getRefreshToken());
79  tokenRequest.setScope(p_oldToken.getScope());
80 
81  Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + tokenPath).request();
82  request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
83  Response response = request
84  .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
85  String entity = response.readEntity(String.class);
86 
87  BaseTest.showResponse("TTokenClient.requestToken() :", response, entity);
88 
89  assertEquals(response.getStatus(), 200, "Unexpected response code.");
90 
91  try {
92  JSONObject jsonObj = new JSONObject(entity);
93  assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
94  assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
95  assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
96  // assertTrue(jsonObj.has("id_token"), "Unexpected result:
97  // id_token not found");
98 
99  String accessToken = jsonObj.getString("access_token");
100  String refreshToken = jsonObj.getString("refresh_token");
101  // String idToken = jsonObj.getString("id_token");
102 
103  final Token newToken = new Token();
104  newToken.setAccessToken(accessToken);
105  newToken.setRefreshToken(refreshToken);
106 
107  t.setT(newToken);
108  } catch (JSONException e) {
109  e.printStackTrace();
110  fail(e.getMessage() + "\nResponse was: " + entity);
111  } catch (Exception e) {
112  e.printStackTrace();
113  fail(e.getMessage());
114  }
115  } catch (Exception e) {
116  e.printStackTrace();
117  fail();
118  }
119 
120  return t.getT();
121  }
final URI baseUri
Definition: TTokenRequest.java:53

◆ pat()

Token org.xdi.oxauth.model.uma.TTokenRequest.pat ( final String  authorizePath,
final String  tokenPath,
final String  userId,
final String  userSecret,
final String  umaClientId,
final String  umaClientSecret,
final String  umaRedirectUri 
)
inline
62  {
63  return internalRequest(authorizePath, tokenPath, userId, userSecret, umaClientId, umaClientSecret,
64  umaRedirectUri, UmaScopeType.PROTECTION);
65  }
Token internalRequest(final String authorizePath, final String tokenPath, final String userId, final String userSecret, final String umaClientId, final String umaClientSecret, final String umaRedirectUri, final UmaScopeType p_scopeType)
Definition: TTokenRequest.java:123

◆ requestAuthorizationCode() [1/2]

void org.xdi.oxauth.model.uma.TTokenRequest.requestAuthorizationCode ( final String  authorizePath,
final String  userId,
final String  userSecret,
final String  umaClientId,
final String  umaRedirectUri,
final UmaScopeType  p_scopeType 
) throws Exception
inlineprivate
140  {
141  requestAuthorizationCode(authorizePath, userId, userSecret, umaClientId, umaRedirectUri,
142  p_scopeType.getValue());
143  }
void requestAuthorizationCode(final String authorizePath, final String userId, final String userSecret, final String umaClientId, final String umaRedirectUri, final UmaScopeType p_scopeType)
Definition: TTokenRequest.java:139

◆ requestAuthorizationCode() [2/2]

void org.xdi.oxauth.model.uma.TTokenRequest.requestAuthorizationCode ( final String  authorizePath,
final String  userId,
final String  userSecret,
final String  umaClientId,
final String  umaRedirectUri,
final String  p_scopeType 
) throws Exception
inlineprivate
146  {
147  List<ResponseType> responseTypes = new ArrayList<ResponseType>();
148  responseTypes.add(ResponseType.CODE);
149  responseTypes.add(ResponseType.ID_TOKEN);
150 
151  List<String> scopes = new ArrayList<String>();
152  scopes.add(p_scopeType);
153 
154  String state = UUID.randomUUID().toString();
155  String nonce = UUID.randomUUID().toString();
156 
157  AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, umaClientId, scopes,
158  umaRedirectUri, nonce);
159  authorizationRequest.setState(state);
160  authorizationRequest.setAuthUsername(userId);
161  authorizationRequest.setAuthPassword(userSecret);
162  authorizationRequest.getPrompts().add(Prompt.NONE);
163 
164  Builder request = ResteasyClientBuilder.newClient()
165  .target(baseUri.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
166  request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
167  request.header("Accept", MediaType.TEXT_PLAIN);
168  Response response = request.get();
169  String entity = response.readEntity(String.class);
170 
171  BaseTest.showResponse("TTokenClient.requestAuthorizationCode() : ", response, entity);
172 
173  assertEquals(response.getStatus(), 302, "Unexpected response code.");
174  assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());
175 
176  if (response.getLocation() != null) {
177  try {
178  final String location = response.getLocation().toString();
179  final int fragmentIndex = location.indexOf("#");
180 
181  Map<String, String> params = new HashMap<String, String>();
182  if (fragmentIndex != -1) {
183  String fragment = location.substring(fragmentIndex + 1);
184  params = QueryStringDecoder.decode(fragment);
185  } else {
186  int queryStringIndex = location.indexOf("?");
187  if (queryStringIndex != -1) {
188  String queryString = location.substring(queryStringIndex + 1);
189  params = QueryStringDecoder.decode(queryString);
190  }
191  }
192 
193  assertNotNull(params.get("code"), "The code is null");
194  assertNotNull(params.get("scope"), "The scope is null");
195  assertNotNull(params.get("state"), "The state is null");
196 
197  token.setAuthorizationCode(params.get("code"));
198  token.setScope(params.get("scope"));
199  } catch (Exception e) {
200  e.printStackTrace();
201  fail(e.getMessage());
202  }
203  }
204  }
Token setScope(String p_scope)
Definition: Token.java:67
final URI baseUri
Definition: TTokenRequest.java:53
final Token token
Definition: TTokenRequest.java:54
Token setAuthorizationCode(String p_authorizationCode)
Definition: Token.java:40

◆ requestRpt()

RPTResponse org.xdi.oxauth.model.uma.TTokenRequest.requestRpt ( final String  p_rptPath)
inline
255  {
256  final Holder<RPTResponse> h = new Holder<RPTResponse>();
257 
258  try {
259  Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + p_rptPath).request();
260  request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
261  //request.header("Authorization", "Bearer " + p_aat.getAccessToken());
262  Response response = request.post(Entity.form(new Form()));
263  String entity = response.readEntity(String.class);
264 
265  BaseTest.showResponse("UMA : TTokenRequest.requestRpt() : ", response, entity);
266 
267  assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
268  try {
269  String tokenResponse = entity;
270  final JSONObject jsonObj = new JSONObject(tokenResponse);
271  if (jsonObj.has("requesterPermissionTokenResponse")) {
272  tokenResponse = jsonObj.get("requesterPermissionTokenResponse").toString();
273  }
274  System.out.println("Token response = " + tokenResponse);
275  RPTResponse result = ServerUtil.createJsonMapper().readValue(tokenResponse, RPTResponse.class);
276  UmaTestUtil.assert_(result);
277 
278  h.setT(result);
279  } catch (IOException e) {
280  e.printStackTrace();
281  fail();
282  } catch (JSONException e) {
283  e.printStackTrace();
284  fail();
285  }
286  } catch (Exception e) {
287  e.printStackTrace();
288  fail();
289  }
290 
291  return h.getT();
292  }
final URI baseUri
Definition: TTokenRequest.java:53

◆ requestRptStatus()

RptIntrospectionResponse org.xdi.oxauth.model.uma.TTokenRequest.requestRptStatus ( String  p_umaRptStatusPath,
final String  rpt 
)
inline
294  {
295  final Holder<RptIntrospectionResponse> h = new Holder<RptIntrospectionResponse>();
296 
297  try {
298  Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + p_umaRptStatusPath)
299  .request();
300  request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
301  // todo uma2
302 // request.header("Authorization", "Bearer " + p_aat.getAccessToken());
303  Response response = request.post(Entity.form(new Form("token", rpt)));
304  String entity = response.readEntity(String.class);
305 
306  // try {
307  // final String json =
308  // ServerUtil.createJsonMapper().writeValueAsString(rpt);
309  // request.setContent(Util.getBytes(json));
310  // request.setContentType(UmaConstants.JSON_MEDIA_TYPE);
311  // } catch (IOException e) {
312  // e.printStackTrace();
313  // fail();
314  // }
315 
316  BaseTest.showResponse("UMA : TTokenRequest.requestRptStatus() : ", response, entity);
317 
318  assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Unexpected response code.");
319  try {
320  final RptIntrospectionResponse result = ServerUtil.createJsonMapper().readValue(entity,
321  RptIntrospectionResponse.class);
322  Assert.assertNotNull(result);
323 
324  h.setT(result);
325  } catch (IOException e) {
326  e.printStackTrace();
327  fail();
328  }
329  } catch (Exception e) {
330  e.printStackTrace();
331  fail();
332  }
333  return h.getT();
334  }
final URI baseUri
Definition: TTokenRequest.java:53

◆ requestToken()

void org.xdi.oxauth.model.uma.TTokenRequest.requestToken ( final String  tokenPath,
final String  umaClientId,
final String  umaClientSecret,
final String  umaRedirectUri 
) throws Exception
inlineprivate
207  {
208  if (token == null || StringUtils.isBlank(token.getAuthorizationCode())) {
209  throw new IllegalArgumentException("Authorization code is not initialized.");
210  }
211 
212  TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
213  tokenRequest.setCode(token.getAuthorizationCode());
214  tokenRequest.setRedirectUri(umaRedirectUri);
215  tokenRequest.setAuthUsername(umaClientId);
216  tokenRequest.setAuthPassword(umaClientSecret);
217  tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
218  tokenRequest.setScope(token.getScope());
219 
220  Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + tokenPath).request();
221  request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
222  Response response = request
223  .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
224  String entity = response.readEntity(String.class);
225 
226  BaseTest.showResponse("TTokenClient.requestToken() :", response, entity);
227 
228  assertEquals(response.getStatus(), 200, "Unexpected response code.");
229 
230  try {
231  JSONObject jsonObj = new JSONObject(entity);
232  assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
233  assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
234  assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
235  // assertTrue(jsonObj.has("id_token"), "Unexpected result: id_token
236  // not found");
237 
238  String accessToken = jsonObj.getString("access_token");
239  String refreshToken = jsonObj.getString("refresh_token");
240  // String idToken = jsonObj.getString("id_token");
241 
242  token.setAccessToken(accessToken);
243  token.setRefreshToken(refreshToken);
244  // m_token.setIdToken(idToken);
245  } catch (JSONException e) {
246  e.printStackTrace();
247  fail(e.getMessage() + "\nResponse was: " + entity);
248  } catch (Exception e) {
249  e.printStackTrace();
250  fail(e.getMessage());
251  }
252  }
String getAuthorizationCode()
Definition: Token.java:36
Token setAccessToken(String p_accessToken)
Definition: Token.java:58
final URI baseUri
Definition: TTokenRequest.java:53
String getScope()
Definition: Token.java:63
final Token token
Definition: TTokenRequest.java:54
Token setRefreshToken(String p_refreshToken)
Definition: Token.java:49

メンバ詳解

◆ baseUri

final URI org.xdi.oxauth.model.uma.TTokenRequest.baseUri
private

◆ token

final Token org.xdi.oxauth.model.uma.TTokenRequest.token = new Token()
private

このクラス詳解は次のファイルから抽出されました: