Search in sources :

Example 1 with JettyHttpFacade

use of org.keycloak.adapters.jetty.spi.JettyHttpFacade in project keycloak by keycloak.

the class AbstractKeycloakJettyAuthenticator method logoutCurrent.

public void logoutCurrent(Request request) {
    AdapterDeploymentContext deploymentContext = (AdapterDeploymentContext) request.getAttribute(AdapterDeploymentContext.class.getName());
    KeycloakSecurityContext ksc = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());
    if (ksc != null) {
        JettyHttpFacade facade = new OIDCJettyHttpFacade(request, null);
        KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade);
        if (ksc instanceof RefreshableKeycloakSecurityContext) {
            ((RefreshableKeycloakSecurityContext) ksc).logout(deployment);
        }
        AdapterTokenStore tokenStore = getTokenStore(request, facade, deployment);
        tokenStore.logout();
        request.removeAttribute(KeycloakSecurityContext.class.getName());
    }
}
Also used : KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) AdapterDeploymentContext(org.keycloak.adapters.AdapterDeploymentContext) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) JettyHttpFacade(org.keycloak.adapters.jetty.spi.JettyHttpFacade) AdapterTokenStore(org.keycloak.adapters.AdapterTokenStore)

Example 2 with JettyHttpFacade

use of org.keycloak.adapters.jetty.spi.JettyHttpFacade in project keycloak by keycloak.

the class AbstractSamlAuthenticator method validateRequest.

@Override
public Authentication validateRequest(ServletRequest req, ServletResponse res, boolean mandatory) throws ServerAuthException {
    if (log.isTraceEnabled()) {
        log.trace("*** authenticate");
    }
    Request request = resolveRequest(req);
    JettyHttpFacade facade = new JettyHttpFacade(request, (HttpServletResponse) res);
    SamlDeployment deployment = deploymentContext.resolveDeployment(facade);
    if (deployment == null || !deployment.isConfigured()) {
        log.debug("*** deployment isn't configured return false");
        return Authentication.UNAUTHENTICATED;
    }
    boolean isEndpoint = request.getRequestURI().substring(request.getContextPath().length()).endsWith("/saml");
    if (!mandatory && !isEndpoint)
        return new DeferredAuthentication(this);
    JettySamlSessionStore tokenStore = getTokenStore(request, facade, deployment);
    SamlAuthenticator authenticator = null;
    if (isEndpoint) {
        authenticator = new SamlAuthenticator(facade, deployment, tokenStore) {

            @Override
            protected void completeAuthentication(SamlSession account) {
            }

            @Override
            protected SamlAuthenticationHandler createBrowserHandler(HttpFacade facade, SamlDeployment deployment, SamlSessionStore sessionStore) {
                return new SamlEndpoint(facade, deployment, sessionStore);
            }
        };
    } else {
        authenticator = new SamlAuthenticator(facade, deployment, tokenStore) {

            @Override
            protected void completeAuthentication(SamlSession account) {
            }

            @Override
            protected SamlAuthenticationHandler createBrowserHandler(HttpFacade facade, SamlDeployment deployment, SamlSessionStore sessionStore) {
                return new BrowserHandler(facade, deployment, sessionStore);
            }
        };
    }
    AuthOutcome outcome = authenticator.authenticate();
    if (outcome == AuthOutcome.AUTHENTICATED) {
        if (facade.isEnded()) {
            return Authentication.SEND_SUCCESS;
        }
        SamlSession samlSession = tokenStore.getAccount();
        Authentication authentication = register(request, samlSession);
        return authentication;
    }
    if (outcome == AuthOutcome.LOGGED_OUT) {
        logoutCurrent(request);
        if (deployment.getLogoutPage() != null) {
            forwardToLogoutPage(request, (HttpServletResponse) res, deployment);
        }
        return Authentication.SEND_CONTINUE;
    }
    AuthChallenge challenge = authenticator.getChallenge();
    if (challenge != null) {
        challenge.challenge(facade);
    }
    return Authentication.SEND_CONTINUE;
}
Also used : AuthChallenge(org.keycloak.adapters.spi.AuthChallenge) SamlAuthenticator(org.keycloak.adapters.saml.SamlAuthenticator) HttpFacade(org.keycloak.adapters.spi.HttpFacade) JettyHttpFacade(org.keycloak.adapters.jetty.spi.JettyHttpFacade) SamlSessionStore(org.keycloak.adapters.saml.SamlSessionStore) BrowserHandler(org.keycloak.adapters.saml.profile.webbrowsersso.BrowserHandler) SamlEndpoint(org.keycloak.adapters.saml.profile.webbrowsersso.SamlEndpoint) Request(org.eclipse.jetty.server.Request) ServletRequest(javax.servlet.ServletRequest) JettyHttpFacade(org.keycloak.adapters.jetty.spi.JettyHttpFacade) DeferredAuthentication(org.eclipse.jetty.security.authentication.DeferredAuthentication) AuthOutcome(org.keycloak.adapters.spi.AuthOutcome) SamlDeployment(org.keycloak.adapters.saml.SamlDeployment) SamlSession(org.keycloak.adapters.saml.SamlSession) SamlAuthenticationHandler(org.keycloak.adapters.saml.profile.SamlAuthenticationHandler) DeferredAuthentication(org.eclipse.jetty.security.authentication.DeferredAuthentication) UserAuthentication(org.eclipse.jetty.security.UserAuthentication) Authentication(org.eclipse.jetty.server.Authentication)

Example 3 with JettyHttpFacade

use of org.keycloak.adapters.jetty.spi.JettyHttpFacade in project keycloak by keycloak.

the class AbstractSamlAuthenticator method logoutCurrent.

public void logoutCurrent(Request request) {
    JettyHttpFacade facade = new JettyHttpFacade(request, null);
    SamlDeployment deployment = deploymentContext.resolveDeployment(facade);
    JettySamlSessionStore tokenStore = getTokenStore(request, facade, deployment);
    tokenStore.logoutAccount();
}
Also used : JettyHttpFacade(org.keycloak.adapters.jetty.spi.JettyHttpFacade) SamlDeployment(org.keycloak.adapters.saml.SamlDeployment)

Aggregations

JettyHttpFacade (org.keycloak.adapters.jetty.spi.JettyHttpFacade)3 SamlDeployment (org.keycloak.adapters.saml.SamlDeployment)2 ServletRequest (javax.servlet.ServletRequest)1 UserAuthentication (org.eclipse.jetty.security.UserAuthentication)1 DeferredAuthentication (org.eclipse.jetty.security.authentication.DeferredAuthentication)1 Authentication (org.eclipse.jetty.server.Authentication)1 Request (org.eclipse.jetty.server.Request)1 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)1 AdapterDeploymentContext (org.keycloak.adapters.AdapterDeploymentContext)1 AdapterTokenStore (org.keycloak.adapters.AdapterTokenStore)1 KeycloakDeployment (org.keycloak.adapters.KeycloakDeployment)1 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)1 SamlAuthenticator (org.keycloak.adapters.saml.SamlAuthenticator)1 SamlSession (org.keycloak.adapters.saml.SamlSession)1 SamlSessionStore (org.keycloak.adapters.saml.SamlSessionStore)1 SamlAuthenticationHandler (org.keycloak.adapters.saml.profile.SamlAuthenticationHandler)1 BrowserHandler (org.keycloak.adapters.saml.profile.webbrowsersso.BrowserHandler)1 SamlEndpoint (org.keycloak.adapters.saml.profile.webbrowsersso.SamlEndpoint)1 AuthChallenge (org.keycloak.adapters.spi.AuthChallenge)1 AuthOutcome (org.keycloak.adapters.spi.AuthOutcome)1