Search in sources :

Example 1 with BasicAuthRequestAuthenticator

use of org.keycloak.adapters.BasicAuthRequestAuthenticator in project keycloak by keycloak.

the class JaxrsBearerTokenFilterImpl method bearerAuthentication.

protected void bearerAuthentication(JaxrsHttpFacade facade, ContainerRequestContext request, KeycloakDeployment resolvedDeployment) {
    BearerTokenRequestAuthenticator authenticator = new BearerTokenRequestAuthenticator(resolvedDeployment);
    AuthOutcome outcome = authenticator.authenticate(facade);
    if (outcome == AuthOutcome.NOT_ATTEMPTED && resolvedDeployment.isEnableBasicAuth()) {
        authenticator = new BasicAuthRequestAuthenticator(resolvedDeployment);
        outcome = authenticator.authenticate(facade);
    }
    if (outcome == AuthOutcome.FAILED || outcome == AuthOutcome.NOT_ATTEMPTED) {
        AuthChallenge challenge = authenticator.getChallenge();
        log.fine("Authentication outcome: " + outcome);
        boolean challengeSent = challenge.challenge(facade);
        if (!challengeSent) {
            // Use some default status code
            facade.getResponse().setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
        }
        // Send response now (if not already sent)
        if (!facade.isResponseFinished()) {
            facade.getResponse().end();
        }
        return;
    } else {
        if (verifySslFailed(facade, resolvedDeployment)) {
            return;
        }
    }
    propagateSecurityContext(facade, request, resolvedDeployment, authenticator);
    handleAuthActions(facade, resolvedDeployment);
}
Also used : BearerTokenRequestAuthenticator(org.keycloak.adapters.BearerTokenRequestAuthenticator) AuthChallenge(org.keycloak.adapters.spi.AuthChallenge) AuthOutcome(org.keycloak.adapters.spi.AuthOutcome) BasicAuthRequestAuthenticator(org.keycloak.adapters.BasicAuthRequestAuthenticator)

Aggregations

BasicAuthRequestAuthenticator (org.keycloak.adapters.BasicAuthRequestAuthenticator)1 BearerTokenRequestAuthenticator (org.keycloak.adapters.BearerTokenRequestAuthenticator)1 AuthChallenge (org.keycloak.adapters.spi.AuthChallenge)1 AuthOutcome (org.keycloak.adapters.spi.AuthOutcome)1