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

公開メンバ関数

 AuthorizeClient (String url)
 
String getHttpMethod ()
 
AuthorizationResponse execAuthorizationCodeGrant (String clientId, List< String > scopes, String redirectUri, String nonce, String state, String req, String reqUri, Display display, List< Prompt > prompt)
 
AuthorizationResponse execImplicitGrant (String clientId, List< String > scopes, String redirectUri, String nonce, String state, String req, String reqUri, Display display, List< Prompt > prompt)
 
AuthorizationResponse exec ()
 
AuthorizationResponse exec (ClientExecutor clientExecutor)
 
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 String NO_REDIRECT_HEADER = "X-Gluu-NoRedirect"
 

非公開メンバ関数

AuthorizationResponse exec_ () throws Exception
 

静的非公開変数類

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

詳解

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

著者
Javier Rojas Blum
バージョン
August 9, 2017

構築子と解体子

◆ AuthorizeClient()

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

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

引数
urlThe REST Service location.
41  {
42  super(url);
43  }

関数詳解

◆ 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  }

◆ 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  }
ClientResponse< String > clientResponse
Definition: BaseClient.java:43

◆ exec() [1/2]

AuthorizationResponse org.xdi.oxauth.client.AuthorizeClient.exec ( )
inline

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

戻り値
The authorization response.
167  {
168  AuthorizationResponse response = null;
169 
170  try {
172  response = exec_();
173  } catch (Exception e) {
174  LOG.error(e.getMessage(), e);
175  } finally {
176  closeConnection();
177  }
178 
179  return response;
180  }
static final Logger LOG
Definition: AuthorizeClient.java:31
AuthorizationResponse exec_()
Definition: AuthorizeClient.java:197

◆ exec() [2/2]

AuthorizationResponse org.xdi.oxauth.client.AuthorizeClient.exec ( ClientExecutor  clientExecutor)
inline
183  {
184  AuthorizationResponse response = null;
185 
186  try {
187  clientRequest = new ClientRequest(getUrl(), clientExecutor);
188  response = exec_();
189  } catch (Exception e) {
190  LOG.error(e.getMessage(), e);
191  }
192  // Do not close the connection for this case.
193 
194  return response;
195  }
static final Logger LOG
Definition: AuthorizeClient.java:31
AuthorizationResponse exec_()
Definition: AuthorizeClient.java:197

◆ exec_()

AuthorizationResponse org.xdi.oxauth.client.AuthorizeClient.exec_ ( ) throws Exception
inlineprivate
197  {
198  // Prepare request parameters
199  clientRequest.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
200  clientRequest.setHttpMethod(getHttpMethod());
201 
202  if (getRequest().isUseNoRedirectHeader()) {
203  clientRequest.header(NO_REDIRECT_HEADER, "true");
204  }
205 
206  final String responseTypesAsString = getRequest().getResponseTypesAsString();
207  final String scopesAsString = getRequest().getScopesAsString();
208  final String promptsAsString = getRequest().getPromptsAsString();
209  final String uiLocalesAsString = getRequest().getUiLocalesAsString();
210  final String claimLocalesAsString = getRequest().getClaimsLocalesAsString();
211  final String acrValuesAsString = getRequest().getAcrValuesAsString();
212  final String claimsAsString = getRequest().getClaimsAsString();
213 
214  addReqParam(AuthorizeRequestParam.RESPONSE_TYPE, responseTypesAsString);
215  addReqParam(AuthorizeRequestParam.CLIENT_ID, getRequest().getClientId());
216  addReqParam(AuthorizeRequestParam.SCOPE, scopesAsString);
217  addReqParam(AuthorizeRequestParam.REDIRECT_URI, getRequest().getRedirectUri());
218  addReqParam(AuthorizeRequestParam.STATE, getRequest().getState());
219 
220  addReqParam(AuthorizeRequestParam.NONCE, getRequest().getNonce());
221  addReqParam(AuthorizeRequestParam.DISPLAY, getRequest().getDisplay());
222  addReqParam(AuthorizeRequestParam.PROMPT, promptsAsString);
223  if (getRequest().getMaxAge() != null) {
224  addReqParam(AuthorizeRequestParam.MAX_AGE, getRequest().getMaxAge().toString());
225  }
226  addReqParam(AuthorizeRequestParam.UI_LOCALES, uiLocalesAsString);
227  addReqParam(AuthorizeRequestParam.CLAIMS_LOCALES, claimLocalesAsString);
228  addReqParam(AuthorizeRequestParam.ID_TOKEN_HINT, getRequest().getIdTokenHint());
229  addReqParam(AuthorizeRequestParam.LOGIN_HINT, getRequest().getLoginHint());
230  addReqParam(AuthorizeRequestParam.ACR_VALUES, acrValuesAsString);
231  addReqParam(AuthorizeRequestParam.CLAIMS, claimsAsString);
232  addReqParam(AuthorizeRequestParam.REGISTRATION, getRequest().getRegistration());
233  addReqParam(AuthorizeRequestParam.REQUEST, getRequest().getRequest());
234  addReqParam(AuthorizeRequestParam.REQUEST_URI, getRequest().getRequestUri());
235  addReqParam(AuthorizeRequestParam.ACCESS_TOKEN, getRequest().getAccessToken());
236  addReqParam(AuthorizeRequestParam.CUSTOM_RESPONSE_HEADERS, getRequest().getCustomResponseHeadersAsString());
237 
238  // PKCE
239  addReqParam(AuthorizeRequestParam.CODE_CHALLENGE, getRequest().getCodeChallenge());
240  addReqParam(AuthorizeRequestParam.CODE_CHALLENGE_METHOD, getRequest().getCodeChallengeMethod());
241 
242  if (getRequest().isRequestSessionId()) {
243  addReqParam(AuthorizeRequestParam.REQUEST_SESSION_ID, Boolean.toString(getRequest().isRequestSessionId()));
244  }
245  addReqParam(AuthorizeRequestParam.SESSION_ID, getRequest().getSessionId());
246 
247  // Custom params
248  for (String key : request.getCustomParameters().keySet()) {
249  addReqParam(key, request.getCustomParameters().get(key));
250  }
251 
252  if (request.getAuthorizationMethod() != AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER && request.hasCredentials()) {
253  clientRequest.header("Authorization", "Basic " + request.getEncodedCredentials());
254  }
255 
256  // Call REST Service and handle response
257  if (request.getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) {
258  clientResponse = clientRequest.post(String.class);
259  } else {
260  clientResponse = clientRequest.get(String.class);
261  }
262 
263  setResponse(new AuthorizationResponse(clientResponse));
264 
265  return getResponse();
266  }
static String NO_REDIRECT_HEADER
Definition: AuthorizeClient.java:33
String getHttpMethod()
Definition: AuthorizeClient.java:46
void addReqParam(String p_key, HasParamName p_value)
Definition: BaseClient.java:88
ClientResponse< String > clientResponse
Definition: BaseClient.java:43

◆ execAuthorizationCodeGrant()

AuthorizationResponse org.xdi.oxauth.client.AuthorizeClient.execAuthorizationCodeGrant ( String  clientId,
List< String >  scopes,
String  redirectUri,
String  nonce,
String  state,
String  req,
String  reqUri,
Display  display,
List< Prompt prompt 
)
inline

The authorization code grant type is used to obtain both access tokens and refresh tokens and is optimized for confidential clients. As a redirection-based flow, the client must be capable of interacting with the resource owner's user-agent (typically a web browser) and capable of receiving incoming requests (via redirection) from the authorization server.

引数
clientIdThe client identifier. This parameter is required.
scopesThe scope of the access request. This parameter is optional.
redirectUriThe redirection URI. This parameter is optional.
nonceA string value used to associate a user agent session with an ID Token, and to mitigate replay attacks. forgery. This parameter is recommended.
stateAn opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client. The parameter should be used for preventing cross-site request forgery.
reqA JWT encoded OpenID Request Object.
reqUriAn URL that points to an OpenID Request Object.
displayAn ASCII string value that specifies how the Authorization Server displays the authentication page to the End-User.
promptA space delimited list of ASCII strings that can contain the values login, consent, select_account, and none.
戻り値
The authorization response.
85  {
86  List<ResponseType> responseTypes = new ArrayList<ResponseType>();
87  responseTypes.add(ResponseType.CODE);
88  setRequest(new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce));
89  getRequest().setRedirectUri(redirectUri);
90  getRequest().setState(state);
91  getRequest().setRequest(req);
92  getRequest().setRedirectUri(reqUri);
93  getRequest().setDisplay(display);
94  getRequest().getPrompts().addAll(prompt);
95 
96  return exec();
97  }
AuthorizationResponse exec()
Definition: AuthorizeClient.java:167

◆ execImplicitGrant()

AuthorizationResponse org.xdi.oxauth.client.AuthorizeClient.execImplicitGrant ( String  clientId,
List< String >  scopes,
String  redirectUri,
String  nonce,
String  state,
String  req,
String  reqUri,
Display  display,
List< Prompt prompt 
)
inline

The implicit grant type is used to obtain access tokens (it does not support the issuance of refresh tokens) and is optimized for public clients known to operate a particular redirection URI. These clients are typically implemented in a browser using a scripting language such as JavaScript.

As a redirection-based flow, the client must be capable of interacting with the resource owner's user-agent (typically a web browser) and capable of receiving incoming requests (via redirection) from the authorization server.

Unlike the authorization code grant type in which the client makes separate requests for authorization and access token, the client receives the access token as the result of the authorization request.

The implicit grant type does not include client authentication, and relies on the presence of the resource owner and the registration of the redirection URI. Because the access token is encoded into the redirection URI, it may be exposed to the resource owner and other applications residing on its device.

引数
clientIdThe client identifier. This parameter is required.
scopesThe scope of the access request. This parameter is optional.
redirectUriThe redirection URI. This parameter is optional.
nonceA string value used to associate a user agent session with an ID Token, and to mitigate replay attacks. forgery. This parameter is recommended.
stateAn opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client. The parameter should be used for preventing cross-site request forgery.
reqA JWT encoded OpenID Request Object.
reqUriAn URL that points to an OpenID Request Object.
displayAn ASCII string value that specifies how the Authorization Server displays the authentication page to the End-User.
promptA space delimited list of ASCII strings that can contain the values login, consent, select_account, and none.
戻り値
The authorization response.
148  {
149  List<ResponseType> responseTypes = new ArrayList<ResponseType>();
150  responseTypes.add(ResponseType.TOKEN);
151  setRequest(new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce));
152  getRequest().setRedirectUri(redirectUri);
153  getRequest().setState(state);
154  getRequest().setRequest(req);
155  getRequest().setRedirectUri(reqUri);
156  getRequest().setDisplay(display);
157  getRequest().getPrompts().addAll(prompt);
158 
159  return exec();
160  }
AuthorizationResponse exec()
Definition: AuthorizeClient.java:167

◆ getCookies()

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

◆ getExecutor()

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

◆ 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.AuthorizeClient.getHttpMethod ( )
inline
46  {
47  if (request.getAuthorizationMethod() == null
48  || request.getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD
49  || request.getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) {
50  return HttpMethod.POST;
51  } else { // AuthorizationMethod.URL_QUERY_PARAMETER
52  return HttpMethod.GET;
53  }
54  }

◆ 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  }

◆ 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 Map< String, String > headers
Definition: BaseClient.java:45

◆ 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  }

◆ 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.AuthorizeClient.LOG = Logger.getLogger(AuthorizeClient.class)
staticprivate

◆ NO_REDIRECT_HEADER

String org.xdi.oxauth.client.AuthorizeClient.NO_REDIRECT_HEADER = "X-Gluu-NoRedirect"
staticpackage

◆ 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

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