Search in sources :

Example 1 with SimpleSession

use of org.apache.shiro.session.mgt.SimpleSession in project killbill by killbill.

the class TestJDBCSessionDao method testCRUD.

@Test(groups = "slow")
public void testCRUD() throws Exception {
    // Note! We are testing the do* methods here to bypass the caching layer
    final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao(dbi);
    // Retrieve
    final SimpleSession session = createSession();
    Assert.assertNull(jdbcSessionDao.doReadSession(session.getId()));
    // Create
    final Serializable sessionId = jdbcSessionDao.doCreate(session);
    final Session retrievedSession = jdbcSessionDao.doReadSession(sessionId);
    Assert.assertEquals(retrievedSession, session);
    // Update
    final String newHost = UUID.randomUUID().toString();
    Assert.assertNotEquals(retrievedSession.getHost(), newHost);
    session.setHost(newHost);
    jdbcSessionDao.doUpdate(session);
    Assert.assertEquals(jdbcSessionDao.doReadSession(sessionId).getHost(), newHost);
    // Delete
    jdbcSessionDao.doDelete(session);
    Assert.assertNull(jdbcSessionDao.doReadSession(session.getId()));
}
Also used : Serializable(java.io.Serializable) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Session(org.apache.shiro.session.Session) Test(org.testng.annotations.Test)

Example 2 with SimpleSession

use of org.apache.shiro.session.mgt.SimpleSession in project killbill by killbill.

the class TestJDBCSessionDao method createSession.

private SimpleSession createSession() {
    final SimpleSession simpleSession = new SimpleSession();
    simpleSession.setStartTimestamp(new Date(System.currentTimeMillis() - 5000));
    simpleSession.setLastAccessTime(new Date(System.currentTimeMillis()));
    simpleSession.setTimeout(493934L);
    simpleSession.setHost(UUID.randomUUID().toString());
    simpleSession.setAttribute(UUID.randomUUID().toString(), Short.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID().toString(), Integer.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID().toString(), Long.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    // Test with Serializable objects
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID());
    simpleSession.setAttribute(UUID.randomUUID().toString(), new Date(1242));
    return simpleSession;
}
Also used : SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Date(java.util.Date)

Example 3 with SimpleSession

use of org.apache.shiro.session.mgt.SimpleSession in project killbill by killbill.

the class TestSessionModelDao method testRoundTrip.

@Test(groups = "fast")
public void testRoundTrip() throws Exception {
    final SimpleSession simpleSession = new SimpleSession();
    simpleSession.setStartTimestamp(new Date(System.currentTimeMillis() - 5000));
    simpleSession.setLastAccessTime(new Date(System.currentTimeMillis()));
    simpleSession.setTimeout(493934L);
    simpleSession.setHost(UUID.randomUUID().toString());
    simpleSession.setAttribute(UUID.randomUUID(), Short.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID(), Integer.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID(), Long.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    // Test with Serializable objects
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID());
    simpleSession.setAttribute(UUID.randomUUID().toString(), new Date(1242));
    final SessionModelDao sessionModelDao = new SessionModelDao(simpleSession);
    Assert.assertEquals(sessionModelDao.getTimeout(), simpleSession.getTimeout());
    Assert.assertEquals(sessionModelDao.getHost(), simpleSession.getHost());
    Assert.assertTrue(sessionModelDao.getSessionData().length > 0);
    final Session retrievedSession = sessionModelDao.toSimpleSession();
    Assert.assertEquals(retrievedSession, simpleSession);
}
Also used : SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Date(java.util.Date) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Session(org.apache.shiro.session.Session) Test(org.testng.annotations.Test)

Example 4 with SimpleSession

use of org.apache.shiro.session.mgt.SimpleSession in project graylog2-server by Graylog2.

the class MongoDbSessionDAO method getSimpleSession.

private SimpleSession getSimpleSession(Serializable sessionId, MongoDbSession dbSession) {
    final SimpleSession session = new SimpleSession();
    assignSessionId(session, sessionId);
    session.setHost(dbSession.getHost());
    session.setTimeout(dbSession.getTimeout());
    session.setStartTimestamp(dbSession.getStartTimestamp());
    session.setLastAccessTime(dbSession.getLastAccessTime());
    session.setExpired(dbSession.isExpired());
    session.setAttributes(dbSession.getAttributes());
    return session;
}
Also used : SimpleSession(org.apache.shiro.session.mgt.SimpleSession)

Example 5 with SimpleSession

use of org.apache.shiro.session.mgt.SimpleSession in project killbill by killbill.

the class SessionModelDao method toSimpleSession.

public Session toSimpleSession() throws IOException {
    final SimpleSession simpleSession = new SimpleSession();
    if (id != null) {
        // Make sure to use a String here! It will be used as-is as the key in Ehcache.
        // When retrieving the session, the sessionId will be a String
        // See https://github.com/killbill/killbill/issues/299
        simpleSession.setId(id);
    }
    simpleSession.setStartTimestamp(startTimestamp.toDate());
    simpleSession.setLastAccessTime(lastAccessTime.toDate());
    simpleSession.setTimeout(timeout);
    simpleSession.setHost(host);
    final Map attributes = serializer.deserialize(sessionData);
    //noinspection unchecked
    simpleSession.setAttributes(attributes);
    return simpleSession;
}
Also used : SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SimpleSession (org.apache.shiro.session.mgt.SimpleSession)10 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)3 Test (org.testng.annotations.Test)3 Date (java.util.Date)2 Session (org.apache.shiro.session.Session)2 Test (org.junit.Test)2 RetryException (com.github.rholder.retry.RetryException)1 DuplicateKeyException (com.mongodb.DuplicateKeyException)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Subject (org.apache.shiro.subject.Subject)1