Search in sources :

Example 16 with HttpScope

use of org.wildfly.security.http.HttpScope in project keycloak by keycloak.

the class ElytronSessionTokenStore method isCached.

@Override
public boolean isCached(RequestAuthenticator authenticator) {
    HttpScope session = this.httpFacade.getScope(Scope.SESSION);
    if (session == null || !session.supportsAttachments()) {
        log.debug("session was null, returning null");
        return false;
    }
    ElytronAccount account;
    try {
        account = (ElytronAccount) session.getAttachment(ElytronAccount.class.getName());
    } catch (IllegalStateException e) {
        log.debug("session was invalidated.  Return false.");
        return false;
    }
    if (account == null) {
        log.debug("Account was not in session, returning null");
        return false;
    }
    KeycloakDeployment deployment = httpFacade.getDeployment();
    if (!deployment.getRealm().equals(account.getKeycloakSecurityContext().getRealm())) {
        log.debug("Account in session belongs to a different realm than for this request.");
        return false;
    }
    boolean active = account.checkActive();
    if (!active) {
        active = account.tryRefresh();
    }
    if (active) {
        log.debug("Cached account found");
        restoreRequest();
        httpFacade.authenticationComplete(account, true);
        return true;
    } else {
        log.debug("Refresh failed. Account was not active. Returning null and invalidating Http session");
        try {
            session.setAttachment(KeycloakSecurityContext.class.getName(), null);
            session.setAttachment(ElytronAccount.class.getName(), null);
            session.invalidate();
        } catch (Exception e) {
            log.debug("Failed to invalidate session, might already be invalidated");
        }
        return false;
    }
}
Also used : HttpScope(org.wildfly.security.http.HttpScope) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment)

Example 17 with HttpScope

use of org.wildfly.security.http.HttpScope in project keycloak by keycloak.

the class ElytronCookieTokenStore method saveAccountInfo.

@Override
public void saveAccountInfo(OidcKeycloakAccount account) {
    RefreshableKeycloakSecurityContext secContext = (RefreshableKeycloakSecurityContext) account.getKeycloakSecurityContext();
    CookieTokenStore.setTokenCookie(this.httpFacade.getDeployment(), this.httpFacade, secContext);
    HttpScope exchange = this.httpFacade.getScope(Scope.EXCHANGE);
    exchange.registerForNotification(httpServerScopes -> logout());
    exchange.setAttachment(ElytronAccount.class.getName(), account);
    exchange.setAttachment(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext());
    restoreRequest();
}
Also used : RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) HttpScope(org.wildfly.security.http.HttpScope) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext)

Example 18 with HttpScope

use of org.wildfly.security.http.HttpScope in project keycloak by keycloak.

the class KeycloakHttpServerAuthenticationMechanism method getSessionIdMapperUpdater.

private SessionIdMapperUpdater getSessionIdMapperUpdater(HttpServerRequest request) {
    HttpScope scope = request.getScope(Scope.APPLICATION);
    SessionIdMapperUpdater res = scope == null ? null : (SessionIdMapperUpdater) scope.getAttachment(KeycloakConfigurationServletListener.ADAPTER_SESSION_ID_MAPPER_UPDATER_ATTRIBUTE_ELYTRON);
    return res == null ? this.idMapperUpdater : res;
}
Also used : HttpScope(org.wildfly.security.http.HttpScope) SessionIdMapperUpdater(org.keycloak.adapters.spi.SessionIdMapperUpdater)

Aggregations

HttpScope (org.wildfly.security.http.HttpScope)18 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)7 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)7 SamlSession (org.keycloak.adapters.saml.SamlSession)4 URI (java.net.URI)3 KeycloakDeployment (org.keycloak.adapters.KeycloakDeployment)3 HttpServerExchange (io.undertow.server.HttpServerExchange)2 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)2 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ServletInputStream (javax.servlet.ServletInputStream)2 ServletRequest (javax.servlet.ServletRequest)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)2 AuthenticationError (org.keycloak.adapters.spi.AuthenticationError)2 LogoutError (org.keycloak.adapters.spi.LogoutError)2