443 TokenClient tokenClient1 =
new TokenClient(openIdConfiguration.getTokenEndpoint());
445 log.info(
"Sending request to token endpoint");
447 log.info(
"redirectURI : " + redirectURL);
448 TokenResponse tokenResponse = tokenClient1.execAuthorizationCode(authorizationCode, redirectURL, clientID,
451 log.debug(
" tokenResponse : " + tokenResponse);
452 if (tokenResponse == null) {
453 log.error(
"Get empty token response. User rcan't log into application");
454 return OxTrustConstants.RESULT_NO_PERMISSIONS;
457 log.debug(
" tokenResponse.getErrorType() : " + tokenResponse.getErrorType());
459 String accessToken = tokenResponse.getAccessToken();
460 log.debug(
" accessToken : " + accessToken);
462 String idToken = tokenResponse.getIdToken();
463 log.debug(
" idToken : " + idToken);
465 log.info(
"Session validation successful. User is logged in");
466 UserInfoClient userInfoClient =
new UserInfoClient(openIdConfiguration.getUserInfoEndpoint());
467 UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);
468 if (userInfoResponse == null) {
469 log.error(
"Get empty token response. User can't log into application");
470 return OxTrustConstants.RESULT_NO_PERMISSIONS;
480 jwt = Jwt.parse(idToken);
481 }
catch (InvalidJwtException ex) {
482 log.error(
"Failed to parse id_token");
483 return OxTrustConstants.RESULT_NO_PERMISSIONS;
487 String nonceResponse = (String) jwt.getClaims().getClaim(JwtClaimName.NONCE);
489 if (!StringHelper.equals(nonceSession, nonceResponse)) {
490 log.error(
"User info response : nonce is not matching.");
491 return OxTrustConstants.RESULT_NO_PERMISSIONS;
495 List<String> uidValues = userInfoResponse.getClaims().get(JwtClaimName.USER_NAME);
496 if ((uidValues == null) || (uidValues.size() == 0)) {
497 log.error(
"User info response doesn't contains uid claim");
498 return OxTrustConstants.RESULT_NO_PERMISSIONS;
505 String issuer = openIdConfiguration.getIssuer();
506 String responseIssuer = (String) jwt.getClaims().getClaim(JwtClaimName.ISSUER);
507 if (issuer == null || responseIssuer == null || !issuer.equals(responseIssuer)) {
508 log.error(
"User info response : Issuer.");
509 return OxTrustConstants.RESULT_NO_PERMISSIONS;
512 List<String> acrValues = jwt.getClaims()
513 .getClaimAsStringList(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE);
514 if ((acrValues == null) || (acrValues.size() == 0) || !acrValues.contains(requestAcrValues)) {
515 log.error(
"User info response doesn't contains acr claim");
516 return OxTrustConstants.RESULT_NO_PERMISSIONS;
518 if (!acrValues.contains(requestAcrValues)) {
519 log.error(
"User info response contains acr='{}' claim but expected acr='{}'", acrValues,
521 return OxTrustConstants.RESULT_NO_PERMISSIONS;
525 oauthData.setUserUid(uidValues.get(0));
526 oauthData.setAccessToken(accessToken);
527 oauthData.setAccessTokenExpirationInSeconds(tokenResponse.getExpiresIn());
528 oauthData.setScopes(scopes);
529 oauthData.setIdToken(idToken);
530 oauthData.setSessionState(sessionState);
532 log.info(
"user uid:" + oauthData.getUserUid());
534 return OxTrustConstants.RESULT_SUCCESS;
OpenIdService openIdService
Definition: Authenticator.java:104
OpenIdConfigurationResponse getOpenIdConfiguration()
Definition: OpenIdService.java:66
OauthData getOauthData()
Definition: Identity.java:31
AppConfiguration appConfiguration
Definition: Authenticator.java:110
Map< String, Object > getSessionMap()
Definition: Identity.java:47
Identity identity
Definition: Authenticator.java:83
void setHost(String host)
Definition: OauthData.java:34
Logger log
Definition: Authenticator.java:80