Java Code Examples for org.apache.catalina.Session#expire()

The following examples show how to use org.apache.catalina.Session#expire() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagerBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void expireSession( String sessionId ) {
    Session s=sessions.get(sessionId);
    if( s==null ) {
        if(log.isInfoEnabled())
            log.info("Session not found " + sessionId);
        return;
    }
    s.expire();
}
 
Example 2
Source File: SingleSignOn.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 3
Source File: Benchmarks.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void run() {
    for (int i = 0; i < count; i++) {
        Session session = mgr.createSession(mgr.generateSessionId());
        session.expire();
    }
}
 
Example 4
Source File: ManagerBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void expireSession( String sessionId ) {
    Session s=sessions.get(sessionId);
    if( s==null ) {
        if(log.isInfoEnabled())
            log.info("Session not found " + sessionId);
        return;
    }
    s.expire();
}
 
Example 5
Source File: SingleSignOn.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 6
Source File: Benchmarks.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    for (int i = 0; i < count; i++) {
        Session session = mgr.createSession(mgr.generateSessionId());
        session.expire();
    }
}
 
Example 7
Source File: ManagerBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void expireSession( String sessionId ) {
    Session s=sessions.get(sessionId);
    if( s==null ) {
        if(log.isInfoEnabled())
            log.info("Session not found " + sessionId);
        return;
    }
    s.expire();
}
 
Example 8
Source File: SingleSignOn.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 9
Source File: Benchmarks.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    for (int i = 0; i < count; i++) {
        Session session = mgr.createSession(mgr.generateSessionId());
        session.expire();
    }
}
 
Example 10
Source File: CatalinaSessionTokenStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void checkCurrentToken() {
    Session catalinaSession = request.getSessionInternal(false);
    if (catalinaSession == null) return;
    SerializableKeycloakAccount account = (SerializableKeycloakAccount) catalinaSession.getSession().getAttribute(SerializableKeycloakAccount.class.getName());
    if (account == null) {
        return;
    }

    RefreshableKeycloakSecurityContext session = account.getKeycloakSecurityContext();
    if (session == null) return;

    // just in case session got serialized
    if (session.getDeployment() == null) session.setCurrentRequestInfo(deployment, this);

    if (session.isActive() && !session.getDeployment().isAlwaysRefreshToken()) {
        request.setAttribute(KeycloakSecurityContext.class.getName(), session);
        request.setUserPrincipal(account.getPrincipal());
        request.setAuthType("KEYCLOAK");
        return;
    }

    // FYI: A refresh requires same scope, so same roles will be set.  Otherwise, refresh will fail and token will
    // not be updated
    boolean success = session.refreshExpiredToken(false);
    if (success && session.isActive()) {
        request.setAttribute(KeycloakSecurityContext.class.getName(), session);
        request.setUserPrincipal(account.getPrincipal());
        request.setAuthType("KEYCLOAK");
        return;
    }

    // Refresh failed, so user is already logged out from keycloak. Cleanup and expire our session
    log.fine("Cleanup and expire session " + catalinaSession.getId() + " after failed refresh");
    request.setUserPrincipal(null);
    request.setAuthType(null);
    cleanSession(catalinaSession);
    catalinaSession.expire();
}
 
Example 11
Source File: CatalinaUserSessionManagement.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void logoutSession(Session session) {
    try {
        if (session != null) session.expire();
    } catch (Exception e) {
        log.debug("Session not present or already invalidated.", e);
    }
}
 
Example 12
Source File: PersistentManagerBase.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Look for a session in the Store and, if found, restore
 * it in the Manager's list of active sessions if appropriate.
 * The session will be removed from the Store after swapping
 * in, but will not be added to the active session list if it
 * is invalid or past its expiration.
 *
 * @param id The id of the session that should be swapped in
 * @return restored session, or {@code null}, if none is found
 * @throws IOException an IO error occurred
 */
protected Session swapIn(String id) throws IOException {

    if (store == null)
        return null;

    Object swapInLock = null;

    /*
     * The purpose of this sync and these locks is to make sure that a
     * session is only loaded once. It doesn't matter if the lock is removed
     * and then another thread enters this method and tries to load the same
     * session. That thread will re-create a swapIn lock for that session,
     * quickly find that the session is already in sessions, use it and
     * carry on.
     */
    synchronized (this) {
        swapInLock = sessionSwapInLocks.get(id);
        if (swapInLock == null) {
            swapInLock = new Object();
            sessionSwapInLocks.put(id, swapInLock);
        }
    }

    Session session = null;

    synchronized (swapInLock) {
        // First check to see if another thread has loaded the session into
        // the manager
        session = sessions.get(id);

        if (session == null) {
            Session currentSwapInSession = sessionToSwapIn.get();
            try {
                if (currentSwapInSession == null || !id.equals(currentSwapInSession.getId())) {
                    session = loadSessionFromStore(id);
                    sessionToSwapIn.set(session);

                    if (session != null && !session.isValid()) {
                        log.error(sm.getString("persistentManager.swapInInvalid", id));
                        session.expire();
                        removeSession(id);
                        session = null;
                    }

                    if (session != null) {
                        reactivateLoadedSession(id, session);
                    }
                }
            } finally {
                sessionToSwapIn.remove();
            }
        }
    }

    // Make sure the lock is removed
    synchronized (this) {
        sessionSwapInLocks.remove(id);
    }

    return session;

}