gluu
公開メンバ関数 | 静的公開メンバ関数 | 限定公開メンバ関数 | 限定公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.xdi.oxauth.client.TokenClient クラス
org.xdi.oxauth.client.TokenClient の継承関係図
Inheritance graph
org.xdi.oxauth.client.TokenClient 連携図
Collaboration graph

公開メンバ関数

 TokenClient (String url)
 
String getHttpMethod ()
 
TokenResponse execAuthorizationCode (String code, String redirectUri, String clientId, String clientSecret)
 
TokenResponse execResourceOwnerPasswordCredentialsGrant (String username, String password, String scope, String clientId, String clientSecret)
 
TokenResponse execClientCredentialsGrant (String scope, String clientId, String clientSecret)
 
TokenResponse execExtensionGrant (String grantTypeUri, String assertion, String clientId, String clientSecret)
 
TokenResponse execRefreshToken (String scope, String refreshToken, String clientId, String clientSecret)
 
TokenResponse exec ()
 
String getUrl ()
 
void setUrl (String url)
 
getRequest ()
 
void setRequest (T request)
 
getResponse ()
 
void setResponse (V response)
 
ClientExecutor getExecutor ()
 
void setExecutor (ClientExecutor executor)
 
String getRequestAsString ()
 
String getResponseAsString ()
 
void closeConnection ()
 
List< Cookie > getCookies ()
 
Map< String, String > getHeaders ()
 

静的公開メンバ関数

static void putAllFormParameters (ClientRequest p_clientRequest, BaseRequest p_request)
 

限定公開メンバ関数

void addReqParam (String p_key, HasParamName p_value)
 
void addReqParam (String p_key, String p_value)
 
void initClientRequest ()
 

限定公開変数類

request
 
response
 
ClientRequest clientRequest
 
ClientResponse< String > clientResponse
 
ClientExecutor executor
 

静的非公開変数類

static final Logger LOG = Logger.getLogger(TokenClient.class)
 

詳解

Encapsulates functionality to make token request calls to an authorization server via REST Services.

著者
Javier Rojas Blum
バージョン
June 28, 2017

構築子と解体子

◆ TokenClient()

org.xdi.oxauth.client.TokenClient.TokenClient ( String  url)
inline

Constructs a token client by providing a REST url where the token service is located.

引数
urlThe REST Service location.
34  {
35  super(url);
36  }

関数詳解

◆ addReqParam() [1/2]

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.addReqParam ( String  p_key,
HasParamName  p_value 
)
inlineprotectedinherited
88  {
89  if (p_value != null) {
90  addReqParam(p_key, p_value.getParamName());
91  }
92  }
void addReqParam(String p_key, HasParamName p_value)
Definition: BaseClient.java:88

◆ addReqParam() [2/2]

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.addReqParam ( String  p_key,
String  p_value 
)
inlineprotectedinherited
94  {
95  if (Util.allNotBlank(p_key, p_value)) {
96  if (request.getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) {
97  clientRequest.formParameter(p_key, p_value);
98  } else {
99  clientRequest.queryParameter(p_key, p_value);
100  }
101  }
102  }
ClientRequest clientRequest
Definition: BaseClient.java:42

◆ closeConnection()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.closeConnection ( )
inlineinherited
239  {
240  try {
241  if (clientResponse != null) {
242  clientResponse.releaseConnection();
243  }
244  if (clientRequest != null && clientRequest.getExecutor() != null) {
245  clientRequest.getExecutor().close();
246  }
247  } catch (Exception e) {
248  LOG.error(e.getMessage(), e);
249  }
250  }
static final Logger LOG
Definition: BaseClient.java:36
ClientResponse< String > clientResponse
Definition: BaseClient.java:43
ClientRequest clientRequest
Definition: BaseClient.java:42

◆ exec()

TokenResponse org.xdi.oxauth.client.TokenClient.exec ( )
inline

Executes the call to the REST Service and processes the response.

戻り値
The token response.
218  {
219  // Prepare request parameters
221  if (request.getAuthenticationMethod() == AuthenticationMethod.CLIENT_SECRET_BASIC
222  && request.hasCredentials()) {
223  clientRequest.header("Authorization", "Basic " + request.getEncodedCredentials());
224  }
225  clientRequest.header("Content-Type", request.getContentType());
226  clientRequest.setHttpMethod(getHttpMethod());
227 
228  if (getRequest().getGrantType() != null) {
229  clientRequest.formParameter("grant_type", getRequest().getGrantType());
230  }
231  if (StringUtils.isNotBlank(getRequest().getCode())) {
232  clientRequest.formParameter("code", getRequest().getCode());
233  }
234  if (StringUtils.isNotBlank(getRequest().getCodeVerifier())) {
235  clientRequest.formParameter("code_verifier", getRequest().getCodeVerifier());
236  }
237  if (StringUtils.isNotBlank(getRequest().getRedirectUri())) {
238  clientRequest.formParameter("redirect_uri", getRequest().getRedirectUri());
239  }
240  if (StringUtils.isNotBlank(getRequest().getUsername())) {
241  clientRequest.formParameter("username", getRequest().getUsername());
242  }
243  if (StringUtils.isNotBlank(getRequest().getPassword())) {
244  clientRequest.formParameter("password", getRequest().getPassword());
245  }
246  if (StringUtils.isNotBlank(getRequest().getScope())) {
247  clientRequest.formParameter("scope", getRequest().getScope());
248  }
249  if (StringUtils.isNotBlank(getRequest().getAssertion())) {
250  clientRequest.formParameter("assertion", getRequest().getAssertion());
251  }
252  if (StringUtils.isNotBlank(getRequest().getRefreshToken())) {
253  clientRequest.formParameter("refresh_token", getRequest().getRefreshToken());
254  }
255  if (getRequest().getAuthenticationMethod() == AuthenticationMethod.CLIENT_SECRET_POST) {
256  if (getRequest().getAuthUsername() != null && !getRequest().getAuthUsername().isEmpty()) {
257  clientRequest.formParameter("client_id", getRequest().getAuthUsername());
258  }
259  if (getRequest().getAuthPassword() != null && !getRequest().getAuthPassword().isEmpty()) {
260  clientRequest.formParameter("client_secret", getRequest().getAuthPassword());
261  }
262  } else if (getRequest().getAuthenticationMethod() == AuthenticationMethod.CLIENT_SECRET_JWT ||
263  getRequest().getAuthenticationMethod() == AuthenticationMethod.PRIVATE_KEY_JWT) {
264  clientRequest.formParameter("client_assertion_type", ClientAssertionType.JWT_BEARER);
265  clientRequest.formParameter("client_assertion", getRequest().getClientAssertion());
266  if (getRequest().getAuthUsername() != null && !getRequest().getAuthUsername().isEmpty()) {
267  clientRequest.formParameter("client_id", getRequest().getAuthUsername());
268  }
269  }
270  for (String key : getRequest().getCustomParameters().keySet()) {
271  clientRequest.formParameter(key, getRequest().getCustomParameters().get(key));
272  }
273 
274  // Call REST Service and handle response
275  try {
276  clientResponse = clientRequest.post(String.class);
277 
278  final TokenResponse tokenResponse = new TokenResponse(clientResponse);
279  tokenResponse.injectDataFromJson();
280  setResponse(tokenResponse);
281  } catch (Exception e) {
282  LOG.error(e.getMessage(), e);
283  } finally {
284  closeConnection();
285  }
286 
287  return getResponse();
288  }
static final Logger LOG
Definition: TokenClient.java:26
ClientResponse< String > clientResponse
Definition: BaseClient.java:43
ClientRequest clientRequest
Definition: BaseClient.java:42
String getHttpMethod()
Definition: TokenClient.java:39
void setResponse(V response)
Definition: BaseClient.java:76
void initClientRequest()
Definition: BaseClient.java:225

◆ execAuthorizationCode()

TokenResponse org.xdi.oxauth.client.TokenClient.execAuthorizationCode ( String  code,
String  redirectUri,
String  clientId,
String  clientSecret 
)
inline

Executes the call to the REST Service requesting the authorization and processes the response.

The authorization code is obtained by using an authorization server as an intermediary between the client and resource owner. Instead of requesting authorization directly from the resource owner, the client directs the resource owner to an authorization server (via its user- agent as defined in [RFC2616]), which in turn directs the resource owner back to the client with the authorization code.

Before directing the resource owner back to the client with the authorization code, the authorization server authenticates the resource owner and obtains authorization. Because the resource owner only authenticates with the authorization server, the resource owner's credentials are never shared with the client.

The authorization code provides a few important security benefits such as the ability to authenticate the client, and the transmission of the access token directly to the client without passing it through the resource owner's user-agent, potentially exposing it to others, including the resource owner.

引数
codehe authorization code received from the authorization server. This parameter is required.
redirectUriThe redirection URI. This parameter is required.
clientIdThe client identifier.
clientSecretThe client secret.
戻り値
The token response.
78  {
79  setRequest(new TokenRequest(GrantType.AUTHORIZATION_CODE));
80  getRequest().setCode(code);
81  getRequest().setRedirectUri(redirectUri);
82  getRequest().setAuthUsername(clientId);
83  getRequest().setAuthPassword(clientSecret);
84 
85  return exec();
86  }
TokenResponse exec()
Definition: TokenClient.java:218
void setRequest(T request)
Definition: BaseClient.java:68

◆ execClientCredentialsGrant()

TokenResponse org.xdi.oxauth.client.TokenClient.execClientCredentialsGrant ( String  scope,
String  clientId,
String  clientSecret 
)
inline

Executes the call to the REST Service requesting the authorization and processes the response.

The client can request an access token using only its client credentials when the client is requesting access to the protected resources under its control, or those of another resource owner which has been previously arranged with the authorization server. The client credentials grant type must only be used by confidential clients.

引数
scopeThe scope of the access request. This parameter is optional.
clientIdThe client identifier.
clientSecretThe client secret.
戻り値
The token response.
147  {
148  setRequest(new TokenRequest(GrantType.CLIENT_CREDENTIALS));
149  getRequest().setScope(scope);
150  getRequest().setAuthUsername(clientId);
151  getRequest().setAuthPassword(clientSecret);
152 
153  return exec();
154  }
TokenResponse exec()
Definition: TokenClient.java:218
void setRequest(T request)
Definition: BaseClient.java:68

◆ execExtensionGrant()

TokenResponse org.xdi.oxauth.client.TokenClient.execExtensionGrant ( String  grantTypeUri,
String  assertion,
String  clientId,
String  clientSecret 
)
inline

Executes the call to the REST Service requesting the authorization and processes the response.

The client uses an extension grant type by specifying the grant type using an absolute URI (defined by the authorization server) as the value of the grant_type parameter of the token endpoint, and by adding any additional parameters necessary.

引数
grantTypeUriAbsolute URI.
assertionAssertion grant type.
clientIdThe client identifier.
clientSecretThe client secret.
戻り値
The token response.
175  {
176  GrantType grantType = GrantType.fromString(grantTypeUri);
177  setRequest(new TokenRequest(grantType));
178  getRequest().setAssertion(assertion);
179  getRequest().setAuthUsername(clientId);
180  getRequest().setAuthPassword(clientSecret);
181 
182  return exec();
183  }
TokenResponse exec()
Definition: TokenClient.java:218
void setRequest(T request)
Definition: BaseClient.java:68

◆ execRefreshToken()

TokenResponse org.xdi.oxauth.client.TokenClient.execRefreshToken ( String  scope,
String  refreshToken,
String  clientId,
String  clientSecret 
)
inline

Executes the call to the REST Service requesting the authorization and processes the response.

If the authorization server issued a refresh token to the client, the client can make a request to the token endpoint for a new access token.

引数
scopeThe scope of the access request. This value is optional.
refreshTokenThe refresh token issued to the client. This value is required.
clientIdThe client identifier.
clientSecretThe client secret.
戻り値
The token response.
203  {
204  setRequest(new TokenRequest(GrantType.REFRESH_TOKEN));
205  getRequest().setScope(scope);
206  getRequest().setRefreshToken(refreshToken);
207  getRequest().setAuthUsername(clientId);
208  getRequest().setAuthPassword(clientSecret);
209 
210  return exec();
211  }
TokenResponse exec()
Definition: TokenClient.java:218
void setRequest(T request)
Definition: BaseClient.java:68

◆ execResourceOwnerPasswordCredentialsGrant()

TokenResponse org.xdi.oxauth.client.TokenClient.execResourceOwnerPasswordCredentialsGrant ( String  username,
String  password,
String  scope,
String  clientId,
String  clientSecret 
)
inline

Executes the call to the REST Service requesting the authorization and processes the response.

The resource owner password credentials grant type is suitable in cases where the resource owner has a trust relationship with the client, such as its device operating system or a highly privileged application. The authorization server should take special care when enabling this grant type, and only allow it when other flows are not viable.

The grant type is suitable for clients capable of obtaining the resource owner's credentials (username and password, typically using an interactive form). It is also used to migrate existing clients using direct authentication schemes such as HTTP Basic or Digest authentication to OAuth by converting the stored credentials to an access token.

引数
usernameThe resource owner username. This parameter is required.
passwordThe resource owner password. This parameter is required.
scopeThe scope of the access request. This parameter is optional.
clientIdThe client identifier.
clientSecretThe client secret.
戻り値
The token response.
117  {
118  setRequest(new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS));
119  getRequest().setUsername(username);
120  getRequest().setPassword(password);
121  getRequest().setScope(scope);
122  getRequest().setAuthUsername(clientId);
123  getRequest().setAuthPassword(clientSecret);
124 
125  return exec();
126  }
TokenResponse exec()
Definition: TokenClient.java:218
void setRequest(T request)
Definition: BaseClient.java:68

◆ getCookies()

List<Cookie> org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getCookies ( )
inlineinherited
254  {
255  return cookies;
256  }
final List< Cookie > cookies
Definition: BaseClient.java:44

◆ getExecutor()

ClientExecutor org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getExecutor ( )
inlineinherited
80  {
81  return executor;
82  }
ClientExecutor executor
Definition: BaseClient.java:47

◆ getHeaders()

Map<String, String> org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getHeaders ( )
inlineinherited
258  {
259  return headers;
260  }
final Map< String, String > headers
Definition: BaseClient.java:45

◆ getHttpMethod()

String org.xdi.oxauth.client.TokenClient.getHttpMethod ( )
inline
39  {
40  return HttpMethod.POST;
41  }

◆ getRequest()

T org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getRequest ( )
inlineinherited
64  {
65  return request;
66  }

◆ getRequestAsString()

String org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getRequestAsString ( )
inlineinherited
115  {
116  StringBuilder sb = new StringBuilder();
117 
118  try {
119  URL theUrl = new URL(url);
120 
121  if (getHttpMethod().equals(HttpMethod.POST)) {
122  sb.append(HttpMethod.POST).append(" ").append(theUrl.getPath()).append(" HTTP/1.1");
123  if (StringUtils.isNotBlank(request.getContentType())) {
124  sb.append("\n");
125  sb.append("Content-Type: ").append(request.getContentType());
126  }
127  if (StringUtils.isNotBlank(request.getMediaType())) {
128  sb.append("\n");
129  sb.append("Accept: ").append(request.getMediaType());
130  }
131  sb.append("\n");
132  sb.append("Host: ").append(theUrl.getHost());
133 
134  if (request instanceof AuthorizationRequest) {
135  AuthorizationRequest authorizationRequest = (AuthorizationRequest) request;
136  if (authorizationRequest.isUseNoRedirectHeader()) {
137  sb.append("\n");
138  sb.append("X-Gluu-NoRedirect: true");
139  }
140  }
141  if (request.getAuthorizationMethod() == null) {
142  if (request.getAuthenticationMethod() == null
143  || request.getAuthenticationMethod() == AuthenticationMethod.CLIENT_SECRET_BASIC) {
144  if (request.hasCredentials()) {
145  String encodedCredentials = request.getEncodedCredentials();
146  sb.append("\n");
147  sb.append("Authorization: Basic ").append(encodedCredentials);
148  }
149  }
150  } else if (request.getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD) {
151  if (request instanceof UserInfoRequest) {
152  String accessToken = ((UserInfoRequest) request).getAccessToken();
153  sb.append("\n");
154  sb.append("Authorization: Bearer ").append(accessToken);
155  }
156  }
157 
158  sb.append("\n");
159  sb.append("\n");
160  sb.append(request.getQueryString());
161  } else if (getHttpMethod().equals(HttpMethod.GET)) {
162  sb.append("GET ").append(theUrl.getPath());
163  if (StringUtils.isNotBlank(request.getQueryString())) {
164  sb.append("?").append(request.getQueryString());
165  }
166  sb.append(" HTTP/1.1");
167  sb.append("\n");
168  sb.append("Host: ").append(theUrl.getHost());
169 
170  if (request instanceof AuthorizationRequest) {
171  AuthorizationRequest authorizationRequest = (AuthorizationRequest) request;
172  if (authorizationRequest.isUseNoRedirectHeader()) {
173  sb.append("\n");
174  sb.append("X-Gluu-NoRedirect: true");
175  }
176  }
177  if (request.getAuthorizationMethod() == null) {
178  if (request.hasCredentials()) {
179  String encodedCredentials = request.getEncodedCredentials();
180  sb.append("\n");
181  sb.append("Authorization: Basic ").append(encodedCredentials);
182  } else if (request instanceof RegisterRequest) {
183  RegisterRequest r = (RegisterRequest) request;
184  String registrationAccessToken = r.getRegistrationAccessToken();
185  sb.append("\n");
186  sb.append("Authorization: Bearer ").append(registrationAccessToken);
187  }
188  } else if (request.getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD) {
189  if (request instanceof UserInfoRequest) {
190  String accessToken = ((UserInfoRequest) request).getAccessToken();
191  sb.append("\n");
192  sb.append("Authorization: Bearer ").append(accessToken);
193  }
194  }
195  }
196  } catch (MalformedURLException e) {
197  LOG.error(e.getMessage(), e);
198  }
199 
200  return sb.toString();
201  }
static final Logger LOG
Definition: BaseClient.java:36

◆ getResponse()

V org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getResponse ( )
inlineinherited
72  {
73  return response;
74  }

◆ getResponseAsString()

String org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getResponseAsString ( )
inlineinherited
203  {
204  StringBuilder sb = new StringBuilder();
205 
206  if (response != null) {
207  sb.append("HTTP/1.1 ").append(response.getStatus());
208  if (response.getHeaders() != null) {
209  for (String key : response.getHeaders().keySet()) {
210  sb.append("\n")
211  .append(key)
212  .append(": ")
213  .append(response.getHeaders().get(key).get(0));
214  }
215  }
216  if (response.getEntity() != null) {
217  sb.append("\n");
218  sb.append("\n");
219  sb.append(response.getEntity());
220  }
221  }
222  return sb.toString();
223  }

◆ getUrl()

String org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.getUrl ( )
inlineinherited
56  {
57  return url;
58  }

◆ initClientRequest()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.initClientRequest ( )
inlineprotectedinherited
225  {
226  if (this.executor == null) {
227  this.clientRequest = new ClientRequest(getUrl());
228  } else {
229  this.clientRequest = new ClientRequest(getUrl(), this.executor);
230  }
231  for (Cookie cookie : cookies) {
232  clientRequest.cookie(cookie);
233  }
234  for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
235  clientRequest.header(headerEntry.getKey(), headerEntry.getValue());
236  }
237  }
final List< Cookie > cookies
Definition: BaseClient.java:44
ClientExecutor executor
Definition: BaseClient.java:47
final Map< String, String > headers
Definition: BaseClient.java:45
ClientRequest clientRequest
Definition: BaseClient.java:42

◆ putAllFormParameters()

static void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.putAllFormParameters ( ClientRequest  p_clientRequest,
BaseRequest  p_request 
)
inlinestaticinherited
104  {
105  if (p_clientRequest != null && p_request != null) {
106  final Map<String, String> parameters = p_request.getParameters();
107  if (parameters != null && !parameters.isEmpty()) {
108  for (Map.Entry<String, String> e : parameters.entrySet()) {
109  p_clientRequest.formParameter(e.getKey(), e.getValue());
110  }
111  }
112  }
113  }

◆ setExecutor()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.setExecutor ( ClientExecutor  executor)
inlineinherited
84  {
85  this.executor = executor;
86  }
ClientExecutor executor
Definition: BaseClient.java:47

◆ setRequest()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.setRequest ( request)
inlineinherited
68  {
69  this.request = request;
70  }

◆ setResponse()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.setResponse ( response)
inlineinherited
76  {
77  this.response = response;
78  }

◆ setUrl()

void org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.setUrl ( String  url)
inlineinherited
60  {
61  this.url = url;
62  }

メンバ詳解

◆ clientRequest

ClientRequest org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.clientRequest
protectedinherited

◆ clientResponse

ClientResponse<String> org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.clientResponse
protectedinherited

◆ executor

ClientExecutor org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.executor
protectedinherited

◆ LOG

final Logger org.xdi.oxauth.client.TokenClient.LOG = Logger.getLogger(TokenClient.class)
staticprivate

◆ request

T org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.request
protectedinherited

◆ response

V org.xdi.oxauth.client.BaseClient< T extends BaseRequest, V extends BaseResponse >.response
protectedinherited

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