Search in sources :

Example 1 with Session

use of org.apache.catalina.Session in project redisson by redisson.

the class RedissonSessionManager method findSession.

@Override
public Session findSession(String id) throws IOException {
    Session result = super.findSession(id);
    if (result == null && id != null) {
        RedissonSession session = (RedissonSession) createEmptySession();
        session.setId(id);
        session.load();
        return session;
    }
    return result;
}
Also used : Session(org.apache.catalina.Session)

Example 2 with Session

use of org.apache.catalina.Session in project keycloak by keycloak.

the class CatalinaSamlSessionStore method logoutAccount.

@Override
public void logoutAccount() {
    Session sessionInternal = request.getSessionInternal(false);
    if (sessionInternal == null)
        return;
    HttpSession session = sessionInternal.getSession();
    List<String> ids = new LinkedList<String>();
    if (session != null) {
        SamlSession samlSession = (SamlSession) session.getAttribute(SamlSession.class.getName());
        if (samlSession != null) {
            if (samlSession.getSessionIndex() != null) {
                ids.add(session.getId());
                idMapperUpdater.removeSession(idMapper, session.getId());
            }
            session.removeAttribute(SamlSession.class.getName());
        }
        session.removeAttribute(SAML_REDIRECT_URI);
    }
    sessionInternal.setPrincipal(null);
    sessionInternal.setAuthType(null);
    logoutSessionIds(ids);
}
Also used : HttpSession(javax.servlet.http.HttpSession) LinkedList(java.util.LinkedList) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.catalina.Session)

Example 3 with Session

use of org.apache.catalina.Session in project keycloak by keycloak.

the class CatalinaSessionTokenStore method isCached.

@Override
public boolean isCached(RequestAuthenticator authenticator) {
    Session session = request.getSessionInternal(false);
    if (session == null)
        return false;
    SerializableKeycloakAccount account = (SerializableKeycloakAccount) session.getSession().getAttribute(SerializableKeycloakAccount.class.getName());
    if (account == null) {
        return false;
    }
    log.fine("remote logged in already. Establish state from session");
    RefreshableKeycloakSecurityContext securityContext = account.getKeycloakSecurityContext();
    if (!deployment.getRealm().equals(securityContext.getRealm())) {
        log.fine("Account from cookie is from a different realm than for the request.");
        cleanSession(session);
        return false;
    }
    securityContext.setCurrentRequestInfo(deployment, this);
    request.setAttribute(KeycloakSecurityContext.class.getName(), securityContext);
    GenericPrincipal principal = (GenericPrincipal) session.getPrincipal();
    // in clustered environment in JBossWeb, principal is not serialized or saved
    if (principal == null) {
        principal = principalFactory.createPrincipal(request.getContext().getRealm(), account.getPrincipal(), account.getRoles());
        session.setPrincipal(principal);
        session.setAuthType("KEYCLOAK");
    }
    request.setUserPrincipal(principal);
    request.setAuthType("KEYCLOAK");
    restoreRequest();
    return true;
}
Also used : GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) Session(org.apache.catalina.Session)

Example 4 with Session

use of org.apache.catalina.Session in project keycloak by keycloak.

the class CatalinaUserSessionManagement method sessionEvent.

public void sessionEvent(SessionEvent event) {
    // We only care about session destroyed events
    if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType()))
        return;
    // Look up the single session id associated with this session (if any)
    Session session = event.getSession();
    log.debugf("Session %s destroyed", session.getId());
    GenericPrincipal principal = (GenericPrincipal) session.getPrincipal();
    if (principal == null)
        return;
    session.setPrincipal(null);
    session.setAuthType(null);
}
Also used : GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) Session(org.apache.catalina.Session)

Example 5 with Session

use of org.apache.catalina.Session in project keycloak by keycloak.

the class CatalinaUserSessionManagement method logoutSession.

protected void logoutSession(Manager manager, String httpSessionId) {
    log.debug("logoutHttpSession: " + httpSessionId);
    Session session;
    try {
        session = manager.findSession(httpSessionId);
    } catch (IOException ioe) {
        log.warn("IO exception when looking for session " + httpSessionId, ioe);
        return;
    }
    logoutSession(session);
}
Also used : IOException(java.io.IOException) Session(org.apache.catalina.Session)

Aggregations

Session (org.apache.catalina.Session)106 IOException (java.io.IOException)24 Manager (org.apache.catalina.Manager)22 Context (org.apache.catalina.Context)16 HttpSession (javax.servlet.http.HttpSession)13 StringManager (org.apache.tomcat.util.res.StringManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpSession (jakarta.servlet.http.HttpSession)7 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)7 Principal (java.security.Principal)6 Realm (org.apache.catalina.Realm)6 StandardContext (org.apache.catalina.core.StandardContext)6 ClusterSession (org.apache.catalina.ha.ClusterSession)6 DeltaSession (org.apache.catalina.ha.session.DeltaSession)6 Container (org.apache.catalina.Container)5 ArrayList (java.util.ArrayList)4 StandardSession (org.apache.catalina.session.StandardSession)4 BufferedOutputStream (java.io.BufferedOutputStream)3 File (java.io.File)3 ObjectOutputStream (java.io.ObjectOutputStream)3