Search in sources :

Example 1 with UndertowHttpFacade

use of org.keycloak.adapters.undertow.UndertowHttpFacade in project keycloak by keycloak.

the class AbstractSamlAuthMech method registerNotifications.

protected void registerNotifications(final SecurityContext securityContext) {
    final NotificationReceiver logoutReceiver = new NotificationReceiver() {

        @Override
        public void handleNotification(SecurityNotification notification) {
            if (notification.getEventType() != SecurityNotification.EventType.LOGGED_OUT)
                return;
            HttpServerExchange exchange = notification.getExchange();
            UndertowHttpFacade facade = createFacade(exchange);
            SamlDeployment deployment = deploymentContext.resolveDeployment(facade);
            SamlSessionStore sessionStore = getTokenStore(exchange, facade, deployment, securityContext);
            sessionStore.logoutAccount();
        }
    };
    securityContext.registerNotificationReceiver(logoutReceiver);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UndertowHttpFacade(org.keycloak.adapters.undertow.UndertowHttpFacade) NotificationReceiver(io.undertow.security.api.NotificationReceiver) SamlSessionStore(org.keycloak.adapters.saml.SamlSessionStore) SamlDeployment(org.keycloak.adapters.saml.SamlDeployment) SecurityNotification(io.undertow.security.api.SecurityNotification)

Example 2 with UndertowHttpFacade

use of org.keycloak.adapters.undertow.UndertowHttpFacade in project keycloak by keycloak.

the class AbstractSamlAuthMech method authenticate.

/**
 * Call this inside your authenticate method.
 */
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
    UndertowHttpFacade facade = createFacade(exchange);
    SamlDeployment deployment = deploymentContext.resolveDeployment(facade);
    if (!deployment.isConfigured()) {
        return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
    }
    SamlSessionStore sessionStore = getTokenStore(exchange, facade, deployment, securityContext);
    SamlAuthenticator authenticator = null;
    if (exchange.getRequestPath().endsWith("/saml")) {
        authenticator = new UndertowSamlEndpoint(facade, deploymentContext.resolveDeployment(facade), sessionStore);
    } else {
        authenticator = new UndertowSamlAuthenticator(securityContext, facade, deploymentContext.resolveDeployment(facade), sessionStore);
    }
    AuthOutcome outcome = authenticator.authenticate();
    if (outcome == AuthOutcome.AUTHENTICATED) {
        registerNotifications(securityContext);
        return AuthenticationMechanismOutcome.AUTHENTICATED;
    }
    if (outcome == AuthOutcome.NOT_AUTHENTICATED) {
        // See KEYCLOAK-2107, AbstractSamlAuthenticationHandler
        return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
    }
    if (outcome == AuthOutcome.LOGGED_OUT) {
        securityContext.logout();
        if (deployment.getLogoutPage() != null) {
            redirectLogout(deployment, exchange);
        }
        return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
    }
    AuthChallenge challenge = authenticator.getChallenge();
    if (challenge != null) {
        exchange.putAttachment(KEYCLOAK_CHALLENGE_ATTACHMENT_KEY, challenge);
        if (authenticator instanceof UndertowSamlEndpoint) {
            exchange.getSecurityContext().setAuthenticationRequired();
        }
    }
    if (outcome == AuthOutcome.FAILED) {
        return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
    }
    return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
Also used : UndertowHttpFacade(org.keycloak.adapters.undertow.UndertowHttpFacade) AuthChallenge(org.keycloak.adapters.spi.AuthChallenge) SamlAuthenticator(org.keycloak.adapters.saml.SamlAuthenticator) SamlSessionStore(org.keycloak.adapters.saml.SamlSessionStore) AuthOutcome(org.keycloak.adapters.spi.AuthOutcome) SamlDeployment(org.keycloak.adapters.saml.SamlDeployment)

Aggregations

SamlDeployment (org.keycloak.adapters.saml.SamlDeployment)2 SamlSessionStore (org.keycloak.adapters.saml.SamlSessionStore)2 UndertowHttpFacade (org.keycloak.adapters.undertow.UndertowHttpFacade)2 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 SecurityNotification (io.undertow.security.api.SecurityNotification)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 SamlAuthenticator (org.keycloak.adapters.saml.SamlAuthenticator)1 AuthChallenge (org.keycloak.adapters.spi.AuthChallenge)1 AuthOutcome (org.keycloak.adapters.spi.AuthOutcome)1