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()));
}
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;
}
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);
}
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;
}
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;
}
Aggregations