use of org.apache.shiro.session.mgt.AbstractSessionManager in project shiro by apache.
the class DefaultWebSecurityManagerTest method testSessionTimeout.
@Test
public void testSessionTimeout() {
shiroSessionModeInit();
long globalTimeout = 100;
((AbstractSessionManager) sm.getSessionManager()).setGlobalSessionTimeout(globalTimeout);
HttpServletRequest mockRequest = createNiceMock(HttpServletRequest.class);
HttpServletResponse mockResponse = createNiceMock(HttpServletResponse.class);
expect(mockRequest.getCookies()).andReturn(null);
expect(mockRequest.getContextPath()).andReturn("/");
replay(mockRequest);
Subject subject = newSubject(mockRequest, mockResponse);
Session session = subject.getSession();
assertEquals(session.getTimeout(), globalTimeout);
session.setTimeout(125);
assertEquals(session.getTimeout(), 125);
sleep(200);
try {
session.getTimeout();
fail("Session should have expired.");
} catch (ExpiredSessionException expected) {
}
}
Aggregations