use of org.apache.shiro.mgt.DefaultSubjectDAO in project neo4j by neo4j.
the class MultiRealmAuthManager method createSubjectDAO.
private SubjectDAO createSubjectDAO() {
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
DefaultSessionStorageEvaluator sessionStorageEvaluator = new DefaultSessionStorageEvaluator();
sessionStorageEvaluator.setSessionStorageEnabled(false);
subjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator);
return subjectDAO;
}
use of org.apache.shiro.mgt.DefaultSubjectDAO in project graylog2-server by Graylog2.
the class UserContextTest method runAs.
@Test
void runAs() {
// Simulate what we do in the DefaultSecurityManagerProvider
DefaultSecurityManager sm = new DefaultSecurityManager();
SecurityUtils.setSecurityManager(sm);
final DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
final DefaultSessionStorageEvaluator sessionStorageEvaluator = new DefaultSessionStorageEvaluator() {
@Override
public boolean isSessionStorageEnabled(Subject subject) {
// save to session if we already have a session. do not create on just for saving the subject
return subject.getSession(false) != null;
}
};
sessionStorageEvaluator.setSessionStorageEnabled(false);
subjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator);
sm.setSubjectDAO(subjectDAO);
final User user = new UserImpl(mock(PasswordAlgorithmFactory.class), mock(Permissions.class), ImmutableMap.of());
when(userService.load(anyString())).thenReturn(user);
when(userService.loadById(anyString())).thenReturn(user);
final String USERID = "123456";
UserContext.<Void>runAs(USERID, () -> {
final UserContext userContext = new UserContext.Factory(userService).create();
assertThat(userContext.getUserId()).isEqualTo(USERID);
assertThat(userContext.getUser()).isEqualTo(user);
return null;
});
}
Aggregations