final Authenticator authenticator = securityManager.getAuthenticator();
if (authenticator instanceof ModularRealmAuthenticator) {
ModularRealmAuthenticator a = (ModularRealmAuthenticator) authenticator;
a.setAuthenticationStrategy(new RethrowingFirstSuccessfulStrategy());
a.setAuthenticationListeners(
Lists.<AuthenticationListener>newArrayList(new PlayAuthenticationListener())
);
}
SecurityUtils.setSecurityManager(securityManager);
}