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

The following examples show how to use org.apache.catalina.Session#getMaxInactiveInterval() . 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: PersistentValve.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Indicate whether the session has been idle for longer
 * than its expiration date as of the supplied time.
 *
 * FIXME: Probably belongs in the Session class.
 * @param session The session to check
 * @param timeNow The current time to check for
 * @return <code>true</code> if the session is past its expiration
 */
protected boolean isSessionStale(Session session, long timeNow) {

    if (session != null) {
        int maxInactiveInterval = session.getMaxInactiveInterval();
        if (maxInactiveInterval >= 0) {
            int timeIdle = // Truncate, do not round up
                (int) ((timeNow - session.getThisAccessedTime()) / 1000L);
            if (timeIdle >= maxInactiveInterval) {
                return true;
            }
        }
    }

    return false;
}
 
Example 2
Source File: PersistentValve.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Indicate whether the session has been idle for longer
 * than its expiration date as of the supplied time.
 *
 * FIXME: Probably belongs in the Session class.
 */
protected boolean isSessionStale(Session session, long timeNow) {

    if (session != null) {
        int maxInactiveInterval = session.getMaxInactiveInterval();
        if (maxInactiveInterval >= 0) {
            int timeIdle = // Truncate, do not round up
                (int) ((timeNow - session.getThisAccessedTime()) / 1000L);
            if (timeIdle >= maxInactiveInterval) {
                return true;
            }
        }
    }

    return false;
}
 
Example 3
Source File: PersistentValve.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Indicate whether the session has been idle for longer
 * than its expiration date as of the supplied time.
 *
 * FIXME: Probably belongs in the Session class.
 */
protected boolean isSessionStale(Session session, long timeNow) {

    if (session != null) {
        int maxInactiveInterval = session.getMaxInactiveInterval();
        if (maxInactiveInterval >= 0) {
            int timeIdle = // Truncate, do not round up
                (int) ((timeNow - session.getThisAccessedTime()) / 1000L);
            if (timeIdle >= maxInactiveInterval) {
                return true;
            }
        }
    }

    return false;
}
 
Example 4
Source File: SessionUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static long getTTLForSession(Session in_session) {
    try {
        long diffMilliSeconds = (1000*in_session.getMaxInactiveInterval()) - (System.currentTimeMillis() - in_session.getThisAccessedTime());
        return diffMilliSeconds;
    } catch (IllegalStateException ise) {
        //ignore: invalidated session
        return -1;
    }
}
 
Example 5
Source File: SingleSignOn.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Process a session destroyed event by removing references to that session
 * from the caches and - if the session destruction is the result of a
 * logout - destroy the associated SSO session.
 *
 * @param ssoId   The ID of the SSO session which which the destroyed
 *                session was associated
 * @param session The session that has been destroyed
 */
public void sessionDestroyed(String ssoId, Session session) {

    if (!getState().isAvailable()) {
        return;
    }

    // Was the session destroyed as the result of a timeout or context stop?
    // If so, we'll just remove the expired session from the SSO. If the
    // session was logged out, we'll log out of all session associated with
    // the SSO.
    if (((session.getMaxInactiveInterval() > 0)
        && (session.getIdleTimeInternal() >= session.getMaxInactiveInterval() * 1000))
        || (!session.getManager().getContext().getState().isAvailable())) {
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionTimeout",
                    ssoId, session));
        }
        removeSession(ssoId, session);
    } else {
        // The session was logged out.
        // Deregister this single session id, invalidating
        // associated sessions
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionLogout",
                    ssoId, session));
        }
        // First remove the session that we know has expired / been logged
        // out since it has already been removed from its Manager and, if
        // we don't remove it first, deregister() will log a warning that it
        // can't be found
        removeSession(ssoId, session);
        // If the SSO session was only associated with one web app the call
        // above will have removed the SSO session from the cache
        if (cache.containsKey(ssoId)) {
            deregister(ssoId);
        }
    }
}
 
Example 6
Source File: SessionUtils.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static long getTTLForSession(Session in_session) {
    try {
        long diffMilliSeconds = (1000*in_session.getMaxInactiveInterval()) - (System.currentTimeMillis() - in_session.getThisAccessedTime());
        return diffMilliSeconds;
    } catch (IllegalStateException ise) {
        //ignore: invalidated session
        return -1;
    }
}
 
Example 7
Source File: SingleSignOn.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Process a session destroyed event by removing references to that session
 * from the caches and - if the session destruction is the result of a
 * logout - destroy the associated SSO session.
 *
 * @param ssoId   The ID of the SSO session which which the destroyed
 *                session was associated
 * @param session The session that has been destroyed
 */
public void sessionDestroyed(String ssoId, Session session) {

    if (!getState().isAvailable()) {
        return;
    }

    // Was the session destroyed as the result of a timeout or context stop?
    // If so, we'll just remove the expired session from the SSO. If the
    // session was logged out, we'll log out of all session associated with
    // the SSO.
    if (((session.getMaxInactiveInterval() > 0)
        && (System.currentTimeMillis() - session.getThisAccessedTimeInternal() >=
            session.getMaxInactiveInterval() * 1000))
        || (!((Context)session.getManager().getContainer()).getState().isAvailable())) {
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionTimeout",
                    ssoId, session));
        }
        removeSession(ssoId, session);
    } else {
        // The session was logged out.
        // Deregister this single session id, invalidating
        // associated sessions
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionLogout",
                    ssoId, session));
        }
        deregister(ssoId);
    }
}
 
Example 8
Source File: SessionUtils.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static long getTTLForSession(Session in_session) {
    try {
        long diffMilliSeconds = (1000*in_session.getMaxInactiveInterval()) - (System.currentTimeMillis() - in_session.getThisAccessedTime());
        return diffMilliSeconds;
    } catch (IllegalStateException ise) {
        //ignore: invalidated session
        return -1;
    }
}
 
Example 9
Source File: SingleSignOn.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Process a session destroyed event by removing references to that session
 * from the caches and - if the session destruction is the result of a
 * logout - destroy the associated SSO session.
 *
 * @param ssoId   The ID of the SSO session which which the destroyed
 *                session was associated
 * @param session The session that has been destroyed
 */
public void sessionDestroyed(String ssoId, Session session) {

    if (!getState().isAvailable()) {
        return;
    }

    // Was the session destroyed as the result of a timeout or context stop?
    // If so, we'll just remove the expired session from the SSO. If the
    // session was logged out, we'll log out of all session associated with
    // the SSO.
    if (((session.getMaxInactiveInterval() > 0)
        && (System.currentTimeMillis() - session.getThisAccessedTimeInternal() >=
            session.getMaxInactiveInterval() * 1000))
        || (!((Context)session.getManager().getContainer()).getState().isAvailable())) {
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionTimeout",
                    ssoId, session));
        }
        removeSession(ssoId, session);
    } else {
        // The session was logged out.
        // Deregister this single session id, invalidating
        // associated sessions
        if (containerLog.isDebugEnabled()) {
            containerLog.debug(sm.getString("singleSignOn.debug.sessionLogout",
                    ssoId, session));
        }
        // First remove the session that we know has expired / been logged
        // out since it has already been removed from its Manager and, if
        // we don't remove it first, deregister() will log a warning that it
        // can't be found
        removeSession(ssoId, session);
        // If the SSO session was only associated with one web app the call
        // above will have removed the SSO session from the cache
        if (cache.containsKey(ssoId)) {
            deregister(ssoId);
        }
    }
}