Example usage for org.apache.shiro.session.mgt SessionManager getSession

List of usage examples for org.apache.shiro.session.mgt SessionManager getSession

Introduction

In this page you can find the example usage for org.apache.shiro.session.mgt SessionManager getSession.

Prototype

Session getSession(SessionKey key) throws SessionException;

Source Link

Document

Retrieves the session corresponding to the specified contextual data (such as a session ID if applicable), or null if no Session could be found.

Usage

From source file:org.obiba.opal.core.runtime.security.AbstractHttpAuthenticatingRealm.java

License:Open Source License

@Nullable
protected Session getSession(String sessionId) {
    if (sessionId != null) {
        SessionManager manager = getSessionManager();
        if (manager != null) {
            SessionKey key = new DefaultSessionKey(sessionId);
            try {
                return manager.getSession(key);
            } catch (SessionException e) {
                // Means that the session does not exist or has expired.
            }//  w  ww  .j  av a 2  s.co  m
        }
    }
    return null;
}

From source file:org.obiba.opal.web.security.SecurityResourceTest.java

License:Open Source License

@Test
public void testCheckSession() {
    Session mockSession = EasyMock.createMock(Session.class);

    SessionManager sessionManager = mockSessionManager();
    expect(sessionManager.getSession(expectSession(testSessionId))).andReturn(mockSession).atLeastOnce();
    replay(sessionManager);/*w  ww.j a v a 2 s  . c  o  m*/

    Response response = securityResource.checkSession(testSessionId);
    Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());

    verify(sessionManager);
}

From source file:org.obiba.opal.web.security.SecurityResourceTest.java

License:Open Source License

@Test
public void testCheckSessionThrowsSessionException() {
    SessionManager sessionManager = mockSessionManager();
    expect(sessionManager.getSession(expectSession(testSessionId))).andThrow(new SessionException())
            .atLeastOnce();// w ww . j  ava2 s. c  o  m
    replay(sessionManager);

    Response response = securityResource.checkSession(testSessionId);
    Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());

    verify(sessionManager);
}

From source file:org.obiba.opal.web.security.SecurityResourceTest.java

License:Open Source License

@Test
public void testCheckSessionReturnsNull() {
    SessionManager sessionManager = mockSessionManager();
    expect(sessionManager.getSession(expectSession(testSessionId))).andReturn(null).atLeastOnce();
    replay(sessionManager);//from  ww  w.ja  va 2s .  c om

    Response response = securityResource.checkSession(testSessionId);
    Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());

    verify(sessionManager);
}