((ModularRealmAuthenticator) authenticator).setAuthenticationStrategy(new FirstSuccessfulStrategy());
}
sm.setAuthorizer(new ModularRealmAuthorizer(Lists.<Realm>newArrayList(mongoDbAuthorizationRealm, inMemoryRealm)));
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 DefaultSessionManager defaultSessionManager = (DefaultSessionManager) sm.getSessionManager();
defaultSessionManager.setSessionDAO(mongoDbSessionDAO);