Хорошо, я нашел другое решение:
1. Инициализировать свой Guice- Модули, как обычно:
public class ConfigServeletWithGuice extends GuiceServletContextListener {
...
@Override
protected Injector getInjector() {
final Injector injector = Guice.createInjector(new ServeletModule(), new BusinessLogicModule(),
new AuthenticationModule(_ctx), new ShiroAopModule(), ShiroWebModule.guiceFilterModule());
final SecurityManager securityManager = injector.getInstance(SecurityManager.class);
SecurityUtils.setSecurityManager(securityManager);
logger.debug("Creation of Injector - done!");
return injector;
}
}
2. Crea т.е собственный SecurityManager:
public class MyWebSecurityManager extends DefaultWebSecurityManager {
@SuppressWarnings("unused")
private static Logger logger = LoggerFactory.getLogger(MyWebSecurityManager.class.getSimpleName());
@Inject
private AuthenticationListener authenticationListener;
public MyWebSecurityManager() {
super();
}
@SuppressWarnings({"UnusedDeclaration"})
public MyWebSecurityManager(Realm singleRealm) {
this();
setRealm(singleRealm);
}
@SuppressWarnings({"UnusedDeclaration"})
public MyWebSecurityManager(Collection realms) {
this();
setRealms(realms);
}
@Override
protected void onSuccessfulLogin(final AuthenticationToken token, final AuthenticationInfo info, final Subject subject) {
super.onSuccessfulLogin(token, info, subject);
logger.debug("onSuccessfulLogin");
authenticationListener.onSuccess(token, info);
}
@Override
protected void onFailedLogin(final AuthenticationToken token, final AuthenticationException ae, final Subject subject) {
super.onFailedLogin(token, ae, subject);
logger.debug("onFailedLogin");
authenticationListener.onFailure(token,ae);
}
@Override
protected void beforeLogout(final Subject subject) {
super.beforeLogout(subject);
logger.debug("beforeLogout");
authenticationListener.onLogout(subject.getPrincipals());
}
}
3. И, наконец, связать свой собственный SecurityManager:
public class AuthenticationModule extends ShiroWebModule {
static Logger logger = LoggerFactory.getLogger(AuthenticationModule.class.getSimpleName());
public AuthenticationModule(final ServletContext sc) {
super(sc);
}
@SuppressWarnings("unchecked")
@Override
protected void configureShiroWeb() {
logger.debug("Start to configure ShiroWeb...");
bind(AuthenticationListener.class).to(AuthenticationListenerImpl.class);
...
logger.debug("configuration ShiroWeb - done!");
}
@Override
// !!!!!! Here it comes:
protected void bindWebSecurityManager(final AnnotatedBindingBuilder bind) {
try {
bind.toConstructor(MyWebSecurityManager.class.getConstructor(Collection.class)).asEagerSingleton();
} catch (NoSuchMethodException e) {
throw new ConfigurationException("This really shouldn't happen. Either something has changed in Shiro, or there's a bug in ShiroModule.", e);
}
}
}
Теперь, после перезагрузки вы должны увидеть сообщение журнала!