102 "Attempting to request access token: grantType = {}, code = {}, redirectUri = {}, username = {}, refreshToken = {}, " +
103 "clientId = {}, ExtraParams = {}, isSecure = {}, codeVerifier = {}, ticket = {}",
104 grantType, code, redirectUri, username, refreshToken, clientId, request.getParameterMap(),
105 sec.isSecure(), codeVerifier, ticket);
107 boolean isUma = StringUtils.isNotBlank(ticket);
112 OAuth2AuditLog oAuth2AuditLog =
new OAuth2AuditLog(
ServerUtil.
getIpAddress(request), Action.TOKEN_REQUEST);
113 oAuth2AuditLog.setClientId(clientId);
114 oAuth2AuditLog.setUsername(username);
115 oAuth2AuditLog.setScope(scope);
117 String tokenBindingHeader = request.getHeader(
"Sec-Token-Binding");
120 ResponseBuilder builder = Response.ok();
123 log.debug(
"Starting to validate request parameters");
124 if (!TokenParamsValidator.validateParams(grantType, code, redirectUri, username, password,
125 scope, assertion, refreshToken)) {
126 log.trace(
"Failed to validate request parameters");
127 builder =
error(400, TokenErrorResponseType.INVALID_REQUEST);
129 log.trace(
"Request parameters are right");
131 log.debug(
"Grant type: '{}'", gt);
135 if (sessionClient != null) {
136 client = sessionClient.getClient();
137 log.debug(
"Get sessionClient: '{}'", sessionClient);
140 if (client != null) {
143 return response(
error(Response.Status.FORBIDDEN.getStatusCode(), TokenErrorResponseType.DISABLED_CLIENT), oAuth2AuditLog);
146 return response(
error(401, TokenErrorResponseType.INVALID_GRANT), oAuth2AuditLog);
149 final Function<JsonWebResponse, Void> idTokenTokingBindingPreprocessing = TokenBindingMessage.createIdTokenTokingBindingPreprocessing(
154 return response(
error(400, TokenErrorResponseType.INVALID_GRANT), oAuth2AuditLog);
157 log.debug(
"Attempting to find authorizationCodeGrant by clinetId: '{}', code: '{}'", client.
getClientId(), code);
159 log.trace(
"AuthorizationCodeGrant : '{}'", authorizationCodeGrant);
161 if (authorizationCodeGrant != null) {
162 validatePKCE(authorizationCodeGrant, codeVerifier, oAuth2AuditLog);
165 authorizationCodeGrant.
save();
168 log.debug(
"Issuing access token: {}", accToken.
getCode());
177 if (scope != null && !scope.isEmpty()) {
182 if (authorizationCodeGrant.
getScopes().contains(
"openid")) {
183 String nonce = authorizationCodeGrant.
getNonce();
184 boolean includeIdTokenClaims = Boolean.TRUE.equals(
187 Function<JsonWebResponse, Void> authorizationCodePreProcessing =
new Function<JsonWebResponse, Void>() {
190 if (StringUtils.isNotBlank(idTokenTokenBindingCnf) && StringUtils.isNotBlank(authorizationCodeGrant.
getTokenBindingHash())) {
191 TokenBindingMessage.setCnfClaim(jsonWebResponse, authorizationCodeGrant.
getTokenBindingHash(), idTokenTokenBindingCnf);
197 nonce, null, accToken, authorizationCodeGrant, includeIdTokenClaims, authorizationCodePreProcessing);
207 oAuth2AuditLog.updateOAuth2AuditLog(authorizationCodeGrant,
true);
211 log.debug(
"AuthorizationCodeGrant is empty by clinetId: '{}', code: '{}'", client.
getClientId(), code);
214 builder =
error(400, TokenErrorResponseType.INVALID_GRANT);
218 return response(
error(400, TokenErrorResponseType.INVALID_GRANT), oAuth2AuditLog);
223 if (authorizationGrant != null) {
234 if (scope != null && !scope.isEmpty()) {
244 oAuth2AuditLog.updateOAuth2AuditLog(authorizationGrant,
true);
246 builder =
error(401, TokenErrorResponseType.INVALID_GRANT);
250 return response(
error(400, TokenErrorResponseType.INVALID_GRANT), oAuth2AuditLog);
257 if (scope != null && !scope.isEmpty()) {
263 boolean includeIdTokenClaims = Boolean.TRUE.equals(
266 null, null, null, clientCredentialsGrant, includeIdTokenClaims, idTokenTokingBindingPreprocessing);
269 oAuth2AuditLog.updateOAuth2AuditLog(clientCredentialsGrant,
true);
278 return response(
error(400, TokenErrorResponseType.INVALID_GRANT), oAuth2AuditLog);
284 if (StringHelper.isNotEmpty(userDn)) {
301 if (scope != null && !scope.isEmpty()) {
307 boolean includeIdTokenClaims = Boolean.TRUE.equals(
309 idToken = resourceOwnerPasswordCredentialsGrant.
createIdToken(
310 null, null, null, resourceOwnerPasswordCredentialsGrant, includeIdTokenClaims, idTokenTokingBindingPreprocessing);
313 oAuth2AuditLog.updateOAuth2AuditLog(resourceOwnerPasswordCredentialsGrant,
true);
321 log.error(
"Invalid user",
new RuntimeException(
"User is empty"));
322 builder =
error(401, TokenErrorResponseType.INVALID_CLIENT);
326 }
catch (WebApplicationException e) {
328 }
catch (SignatureException e) {
329 builder = Response.status(500);
330 log.error(e.getMessage(), e);
331 }
catch (StringEncrypter.EncryptionException e) {
332 builder = Response.status(500);
333 log.error(e.getMessage(), e);
335 builder = Response.status(500);
336 log.error(e.getMessage(), e);
338 builder = Response.status(500);
339 log.error(e.getMessage(), e);
340 }
catch (Exception e) {
341 builder = Response.status(500);
342 log.error(e.getMessage(), e);
345 return response(builder, oAuth2AuditLog);
AuthorizationGrantList authorizationGrantList
Definition: TokenRestWebServiceImpl.java:74
static GrantType fromString(String param)
Definition: GrantType.java:121
AuthorizationCode getAuthorizationCode()
Definition: AbstractAuthorizationGrant.java:105
String getNonce()
Definition: AbstractAuthorizationGrant.java:128
void removeByCode(String p_code, String p_clientId)
Definition: GrantService.java:362
SessionClient getSessionClient()
Definition: Identity.java:50
Definition: RefreshToken.java:45
Boolean getOpenidScopeBackwardCompatibility()
Definition: AppConfiguration.java:1393
AccessToken createAccessToken()
Definition: AuthorizationGrant.java:158
String getClientId()
Definition: Client.java:275
void save()
Definition: AuthorizationGrant.java:103
String getTokenBindingHash()
Definition: AbstractAuthorizationGrant.java:119
GrantType [] getGrantTypes()
Definition: Client.java:456
void validatePKCE(AuthorizationCodeGrant grant, String codeVerifier, OAuth2AuditLog oAuth2AuditLog)
Definition: TokenRestWebServiceImpl.java:348
Definition: GrantType.java:23
static String getIpAddress(HttpServletRequest httpRequest)
Definition: ServerUtil.java:188
ResponseBuilder error(int p_status, TokenErrorResponseType p_type)
Definition: TokenRestWebServiceImpl.java:375
int getExpiresIn()
Definition: AbstractToken.java:230
String checkScopesPolicy(String scope)
Definition: AuthorizationGrant.java:96
UmaTokenService umaTokenService
Definition: TokenRestWebServiceImpl.java:92
void removeAllByAuthorizationCode(String p_authorizationCode)
Definition: GrantService.java:370
REFRESH_TOKEN
Definition: GrantType.java:70
AuthorizationGrant getAuthorizationGrantByRefreshToken(String clientId, String refreshTokenCode)
Definition: AuthorizationGrantList.java:131
String getIdTokenTokenBindingCnf()
Definition: Client.java:534
Boolean getLegacyIdTokenClaims()
Definition: AppConfiguration.java:1265
boolean isDisabled()
Definition: Client.java:1114
AUTHORIZATION_CODE
Definition: GrantType.java:33
Response response(ResponseBuilder builder, OAuth2AuditLog oAuth2AuditLog)
Definition: TokenRestWebServiceImpl.java:363
String processAuthenticationFilters(Map<?, ?> attributeValues)
Definition: BaseAuthFilterService.java:234
Definition: AuthorizationGrant.java:49
Set< GrantType > getGrantTypesSupported()
Definition: AppConfiguration.java:549
UserService userService
Definition: TokenRestWebServiceImpl.java:77
User getAuthenticatedUser()
Definition: AuthenticationService.java:487
ClientCredentialsGrant createClientCredentialsGrant(User user, Client client)
Definition: AuthorizationGrantList.java:104
String getCode()
Definition: AbstractToken.java:112
String getJSonResponse(AccessToken accessToken, TokenType tokenType, Integer expiresIn, RefreshToken refreshToken, String scope, IdToken idToken)
Definition: TokenRestWebServiceImpl.java:382
boolean isEnabled()
Definition: BaseAuthFilterService.java:259
CLIENT_CREDENTIALS
Definition: GrantType.java:64
RESOURCE_OWNER_PASSWORD_CREDENTIALS
Definition: GrantType.java:52
Identity identity
Definition: TokenRestWebServiceImpl.java:65
Response requestRpt(String grantType, String ticket, String claimToken, String claimTokenFormat, String pctCode, String rptCode, String scope, HttpServletRequest httpRequest)
Definition: UmaTokenService.java:80
Definition: AccessToken.java:35
Definition: ServerUtil.java:50
ResourceOwnerPasswordCredentialsGrant createResourceOwnerPasswordCredentialsGrant(User user, Client client)
Definition: AuthorizationGrantList.java:112
AuthorizationCodeGrant getAuthorizationCodeGrant(String clientId, String authorizationCode)
Definition: AuthorizationGrantList.java:120
Logger log
Definition: TokenRestWebServiceImpl.java:62
Definition: InvalidJwtException.java:12
AppConfiguration appConfiguration
Definition: TokenRestWebServiceImpl.java:89
Set< String > getScopes()
Definition: AbstractAuthorizationGrant.java:377
static String urlDecode(String p_str)
Definition: ServerUtil.java:140
Definition: AuthorizationCodeGrant.java:39
String getClientId()
Definition: AbstractAuthorizationGrant.java:345
boolean authenticate(String userName, String password)
Definition: AuthenticationService.java:124
IdToken createIdToken(IAuthorizationGrant grant, String nonce, AuthorizationCode authorizationCode, AccessToken accessToken, Set< String > scopes, boolean includeIdTokenClaims, Function< JsonWebResponse, Void > preProcessing)
Definition: AuthorizationGrant.java:87
Definition: Client.java:37
Definition: InvalidJweException.java:12
Definition: ClientCredentialsGrant.java:24
User getUserByDn(String dn, String... returnAttributes)
Definition: UserService.java:66
TokenType getTokenType()
Definition: AccessToken.java:68
Definition: JsonWebResponse.java:21
AuthenticationFilterService authenticationFilterService
Definition: TokenRestWebServiceImpl.java:83
AuthenticationService authenticationService
Definition: TokenRestWebServiceImpl.java:86
RefreshToken createRefreshToken()
Definition: AuthorizationGrant.java:197
Definition: ResourceOwnerPasswordCredentialsGrant.java:32
GrantService grantService
Definition: TokenRestWebServiceImpl.java:80
void setIsCachedWithNoPersistence(boolean isCachedWithNoPersistence)
Definition: AuthorizationGrant.java:381
Definition: IdToken.java:14