Search in sources :

Example 1 with TokenIntrospectContext

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) TokenIntrospectionProvider(org.keycloak.protocol.oidc.TokenIntrospectionProvider) TokenIntrospectContext(org.keycloak.services.clientpolicy.context.TokenIntrospectContext) ErrorResponseException(org.keycloak.services.ErrorResponseException) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) ErrorResponseException(org.keycloak.services.ErrorResponseException) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) POST(javax.ws.rs.POST) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

POST (javax.ws.rs.POST)1 Response (javax.ws.rs.core.Response)1 NoCache (org.jboss.resteasy.annotations.cache.NoCache)1 TokenIntrospectionProvider (org.keycloak.protocol.oidc.TokenIntrospectionProvider)1 ErrorResponseException (org.keycloak.services.ErrorResponseException)1 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)1 TokenIntrospectContext (org.keycloak.services.clientpolicy.context.TokenIntrospectContext)1