@Test public void testValidateSessions() { final SimpleSession validSession = new SimpleSession(); validSession.setId(1); final SimpleSession invalidSession = new SimpleSession(); Calendar cal = Calendar.getInstance(); Long expiredTimeout = AbstractSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT + 1; cal.add(Calendar.MILLISECOND, -(expiredTimeout.intValue()) ); Date past = cal.getTime(); invalidSession.setStartTimestamp(past); invalidSession.setLastAccessTime(past); invalidSession.setId(2); final AtomicInteger expirationCount = new AtomicInteger(); SessionListener sessionListener = new SessionListenerAdapter() { @Override public void onExpiration(Session session) { expirationCount.incrementAndGet(); } }; AbstractValidatingSessionManager sessionManager = new AbstractValidatingSessionManager() { @Override protected Session retrieveSession(SessionKey key) throws UnknownSessionException { throw new UnsupportedOperationException("Should not be called in this test."); } @Override protected Session doCreateSession(SessionContext initData) throws AuthorizationException { throw new UnsupportedOperationException("Should not be called in this test."); } @Override protected Collection<Session> getActiveSessions() { Collection<Session> sessions = new ArrayList<Session>(2); sessions.add(validSession); sessions.add(invalidSession); return sessions; } }; sessionManager.setSessionListeners(Arrays.asList(sessionListener)); sessionManager.validateSessions(); assertEquals(1, expirationCount.intValue()); }
public void validateSessions() { if (log.isInfoEnabled()) { log.info("Validating all active sessions..."); } int invalidCount = 0; Collection<Session> activeSessions = getActiveSessions(); if (activeSessions != null && !activeSessions.isEmpty()) { for (Session s : activeSessions) { try { SessionKey key = new DefaultSessionKey(s.getId()); validate(s, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; } } } if (log.isInfoEnabled()) { String msg = "Finished session validation."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } }
AbstractValidatingSessionManager extends AbstractNativeSessionManager implements ValidatingSessionManager, Destroyable { public void validateSessions() { if (log.isInfoEnabled()) { log.info("Validating all active sessions..."); } int invalidCount = 0; Collection<Session> activeSessions = getActiveSessions(); if (activeSessions != null && !activeSessions.isEmpty()) { for (Session s : activeSessions) { try { SessionKey key = new DefaultSessionKey(s.getId()); validate(s, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; } } } if (log.isInfoEnabled()) { String msg = "Finished session validation."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } } }
AbstractValidatingSessionManager extends AbstractNativeSessionManager implements ValidatingSessionManager, Destroyable { public void validateSessions() { if (log.isInfoEnabled()) { log.info("Validating all active sessions..."); } int invalidCount = 0; Collection<Session> activeSessions = getActiveSessions(); if (activeSessions != null && !activeSessions.isEmpty()) { for (Session s : activeSessions) { try { SessionKey key = new DefaultSessionKey(s.getId()); validate(s, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; } } } if (log.isInfoEnabled()) { String msg = "Finished session validation."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } } AbstractValidatingSessionManager(); }
AbstractValidatingSessionManager extends AbstractNativeSessionManager implements ValidatingSessionManager, Destroyable { public void validateSessions() { if (log.isInfoEnabled()) { log.info("Validating all active sessions..."); } int invalidCount = 0; Collection<Session> activeSessions = getActiveSessions(); if (activeSessions != null && !activeSessions.isEmpty()) { for (Session s : activeSessions) { try { SessionKey key = new DefaultSessionKey(s.getId()); validate(s, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; } } } if (log.isInfoEnabled()) { String msg = "Finished session validation."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } } AbstractValidatingSessionManager(); boolean isSessionValidationSchedulerEnabled(); @SuppressWarnings({"UnusedDeclaration"}) void setSessionValidationSchedulerEnabled(boolean sessionValidationSchedulerEnabled); void setSessionValidationScheduler(SessionValidationScheduler sessionValidationScheduler); SessionValidationScheduler getSessionValidationScheduler(); void setSessionValidationInterval(long sessionValidationInterval); long getSessionValidationInterval(); void destroy(); void validateSessions(); }
AbstractValidatingSessionManager extends AbstractNativeSessionManager implements ValidatingSessionManager, Destroyable { public void validateSessions() { if (log.isInfoEnabled()) { log.info("Validating all active sessions..."); } int invalidCount = 0; Collection<Session> activeSessions = getActiveSessions(); if (activeSessions != null && !activeSessions.isEmpty()) { for (Session s : activeSessions) { try { SessionKey key = new DefaultSessionKey(s.getId()); validate(s, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + s.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; } } } if (log.isInfoEnabled()) { String msg = "Finished session validation."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } } AbstractValidatingSessionManager(); boolean isSessionValidationSchedulerEnabled(); @SuppressWarnings({"UnusedDeclaration"}) void setSessionValidationSchedulerEnabled(boolean sessionValidationSchedulerEnabled); void setSessionValidationScheduler(SessionValidationScheduler sessionValidationScheduler); SessionValidationScheduler getSessionValidationScheduler(); void setSessionValidationInterval(long sessionValidationInterval); long getSessionValidationInterval(); void destroy(); void validateSessions(); static final long DEFAULT_SESSION_VALIDATION_INTERVAL; }