use of org.keycloak.services.clientpolicy.context.TokenIntrospectContext in project keycloak by keycloak.
the class TokenIntrospectionEndpoint method introspect.
@POST
@NoCache
public Response introspect() {
event.event(EventType.INTROSPECT_TOKEN);
checkSsl();
checkRealm();
authorizeClient();
MultivaluedMap<String, String> formParams = request.getDecodedFormParameters();
checkParameterDuplicated(formParams);
String tokenTypeHint = formParams.getFirst(PARAM_TOKEN_TYPE_HINT);
if (tokenTypeHint == null) {
tokenTypeHint = AccessTokenIntrospectionProviderFactory.ACCESS_TOKEN_TYPE;
}
String token = formParams.getFirst(PARAM_TOKEN);
if (token == null) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, "Token not provided.", Status.BAD_REQUEST);
}
TokenIntrospectionProvider provider = this.session.getProvider(TokenIntrospectionProvider.class, tokenTypeHint);
if (provider == null) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, "Unsupported token type [" + tokenTypeHint + "].", Status.BAD_REQUEST);
}
try {
session.clientPolicy().triggerOnEvent(new TokenIntrospectContext(formParams));
} catch (ClientPolicyException cpe) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, cpe.getErrorDetail(), Status.BAD_REQUEST);
}
try {
Response response = provider.introspect(token);
this.event.success();
return response;
} catch (ErrorResponseException ere) {
throw ere;
} catch (Exception e) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, "Failed to introspect token.", Status.BAD_REQUEST);
}
}
Aggregations