use of org.apache.shiro.session.mgt.SimpleSession in project killbill by killbill.
the class TestJDBCSessionDao method testH2AndInvalidSessionId.
@Test(groups = "slow")
public void testH2AndInvalidSessionId() {
final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao(dbi);
// We need to create some data to force H2 to build the query
// (otherwise, the read path is optimized and the bug is not triggered)
final SimpleSession session = createSession();
jdbcSessionDao.doCreate(session);
// Make sure this doesn't throw any exception on H2
Assert.assertNull(jdbcSessionDao.doReadSession(UUID.randomUUID()));
}
use of org.apache.shiro.session.mgt.SimpleSession in project graylog2-server by Graylog2.
the class MongoDbSessionDAO method doUpdate.
@Override
protected void doUpdate(Session session) {
final MongoDbSession dbSession = mongoDBSessionService.load(session.getId().toString());
if (null == dbSession) {
throw new RuntimeException("Couldn't load session <" + session.getId() + ">");
}
LOG.debug("Updating session {}", session);
dbSession.setHost(session.getHost());
dbSession.setTimeout(session.getTimeout());
dbSession.setStartTimestamp(session.getStartTimestamp());
dbSession.setLastAccessTime(session.getLastAccessTime());
if (session instanceof SimpleSession) {
final SimpleSession simpleSession = (SimpleSession) session;
dbSession.setAttributes(simpleSession.getAttributes());
dbSession.setExpired(simpleSession.isExpired());
} else {
throw new RuntimeException("Unsupported session type: " + session.getClass().getCanonicalName());
}
// Due to https://jira.mongodb.org/browse/SERVER-14322 upserts can fail under concurrency.
// We need to retry the update, and stagger them a bit, so no all of the retries attempt it at the same time again.
// Usually this should succeed the first time, though
final Retryer<Object> retryer = RetryerBuilder.newBuilder().retryIfExceptionOfType(DuplicateKeyException.class).withWaitStrategy(WaitStrategies.randomWait(5, TimeUnit.MILLISECONDS)).withStopStrategy(StopStrategies.stopAfterAttempt(10)).build();
try {
retryer.call(() -> mongoDBSessionService.saveWithoutValidation(dbSession));
} catch (ExecutionException e) {
LOG.warn("Unexpected exception when saving session to MongoDB. Failed to update session.", e);
throw new RuntimeException(e.getCause());
} catch (RetryException e) {
LOG.warn("Tried to update session 10 times, but still failed. This is likely because of https://jira.mongodb.org/browse/SERVER-14322", e);
throw new RuntimeException(e.getCause());
}
}
use of org.apache.shiro.session.mgt.SimpleSession in project ddf by codice.
the class AbstractDownloadsStatusEventPublisherTest method addSecurity.
private void addSecurity() {
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection(USER_ID, "testrealm");
Subject subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
ThreadContext.bind(secManager);
ThreadContext.bind(subject);
}
use of org.apache.shiro.session.mgt.SimpleSession in project ddf by codice.
the class SubjectUtilsTest method testGetName.
@Test
public void testGetName() {
org.apache.shiro.subject.Subject subject;
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection(TEST_NAME, "testrealm");
subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
assertEquals(TEST_NAME, SubjectUtils.getName(subject));
}
use of org.apache.shiro.session.mgt.SimpleSession in project ddf by codice.
the class SubjectUtilsTest method testGetDefaultName.
@Test
public void testGetDefaultName() {
org.apache.shiro.subject.Subject subject;
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection();
subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
assertEquals(DEFAULT_NAME, SubjectUtils.getName(subject, DEFAULT_NAME));
assertEquals(DEFAULT_NAME, SubjectUtils.getName(null, DEFAULT_NAME));
}
Aggregations