95 log.trace(
"Introspect token, authorization: {}, token to introsppect: {}, tokenTypeHint:", p_authorization, p_token, tokenTypeHint);
96 if (StringUtils.isNotBlank(p_authorization) && StringUtils.isNotBlank(p_token)) {
98 if (authorizationGrant != null) {
101 if (authorizationAccessToken != null && authorizationAccessToken.isValid()) {
103 if (!authorizationGrant.getScopesAsString().contains(UmaScopeType.PROTECTION.getValue())) {
104 log.trace(
"access_token used to access introspection endpoint does not has uma_protection scope, however in oxauth configuration `checkUmaProtectionScopePresenceDuringIntrospection` is true");
105 return Response.status(Response.Status.UNAUTHORIZED).entity(
errorResponseFactory.
getErrorAsJson(AuthorizeErrorResponseType.ACCESS_DENIED) +
" access_token does not have uma_protection scope which is required by OP configuration.").build();
108 final IntrospectionResponse response =
new IntrospectionResponse(
false);
111 if (grantOfIntrospectionToken != null) {
112 final AbstractToken tokenToIntrospect = grantOfIntrospectionToken.
getAccessToken(p_token);
113 final User user = grantOfIntrospectionToken.getUser();
115 response.setActive(tokenToIntrospect.isValid());
116 response.setExpiresAt(ServerUtil.dateToSeconds(tokenToIntrospect.getExpirationDate()));
117 response.setIssuedAt(ServerUtil.dateToSeconds(tokenToIntrospect.getCreationDate()));
118 response.setAcrValues(grantOfIntrospectionToken.getAcrValues());
119 response.setScope(grantOfIntrospectionToken.getScopes() != null ? grantOfIntrospectionToken.getScopes() :
new ArrayList<String>());
120 response.setClientId(grantOfIntrospectionToken.getClientId());
121 response.setSub(grantOfIntrospectionToken.getSub());
122 response.setUsername(user != null ? user.getAttribute(
"displayName") : null);
124 response.setAudience(grantOfIntrospectionToken.getClientId());
126 if (tokenToIntrospect instanceof AccessToken) {
127 AccessToken accessToken = (AccessToken) tokenToIntrospect;
128 response.setTokenType(accessToken.getTokenType() != null ? accessToken.getTokenType().getName() : TokenType.BEARER.getName());
131 log.error(
"Failed to find grant for access_token: " + p_token);
134 return Response.status(Response.Status.OK).entity(ServerUtil.asJson(response)).build();
136 log.error(
"Access token is not valid. Valid: " + (authorizationAccessToken != null && authorizationAccessToken.isValid()));
140 log.error(
"Authorization grant is null.");
144 }
catch (Exception e) {
145 log.error(e.getMessage(), e);
146 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
AppConfiguration appConfiguration
Definition: IntrospectionWebService.java:61
String getErrorAsJson(IErrorType p_type)
Definition: ErrorResponseFactory.java:86
AuthorizationGrant getAuthorizationGrant(String authorization, String accessToken)
Definition: IntrospectionWebService.java:152
AuthorizationGrantList authorizationGrantList
Definition: IntrospectionWebService.java:67
Logger log
Definition: IntrospectionWebService.java:59
String getTokenFromAuthorizationParameter(String authorizationParameter)
Definition: TokenService.java:30
AbstractToken getAccessToken(String tokenCode)
Definition: AbstractAuthorizationGrant.java:445
Boolean getIntrospectionAccessTokenMustHaveUmaProtectionScope()
Definition: AppConfiguration.java:213
String getIssuer()
Definition: AppConfiguration.java:274
TokenService tokenService
Definition: IntrospectionWebService.java:63
ErrorResponseFactory errorResponseFactory
Definition: IntrospectionWebService.java:65
AuthorizationGrant getAuthorizationGrantByAccessToken(String accessToken)
Definition: AuthorizationGrantList.java:166