Search in sources :

Example 1 with AbstractSessionManager

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) {
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ExpiredSessionException(org.apache.shiro.session.ExpiredSessionException) AbstractSessionManager(org.apache.shiro.session.mgt.AbstractSessionManager) WebSubject(org.apache.shiro.web.subject.WebSubject) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session) ShiroHttpSession(org.apache.shiro.web.servlet.ShiroHttpSession) Test(org.junit.Test)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ExpiredSessionException (org.apache.shiro.session.ExpiredSessionException)1 Session (org.apache.shiro.session.Session)1 AbstractSessionManager (org.apache.shiro.session.mgt.AbstractSessionManager)1 Subject (org.apache.shiro.subject.Subject)1 ShiroHttpSession (org.apache.shiro.web.servlet.ShiroHttpSession)1 WebSubject (org.apache.shiro.web.subject.WebSubject)1 Test (org.junit.Test)1