I am trying to use a custom authenticator for tapestry-security (org.tynamo.security).
I have a custom authenticator
public class EnvironmentalRealmAuthenticator extends ModularRealmAuthenticator
And in my module I override the default authenticator of Tapestry (ModularRealmAuthenticator
):
public static void bind(final ServiceBinder binder) {
binder.bind(Authenticator.class, EnvironmentalRealmAuthenticator.class).withId("EnvironmentalRealmAuthenticator");
}
@Contribute(ServiceOverride.class)
public static void setupOverrides(final MappedConfiguration<Class, Object> configuration, @Local final Authenticator override) {
configuration.add(Authenticator.class, override);
}
However, this causes the cache to not be cleared on logout - I have the suspicion that this is caused by the way the DefaultSecurityManager
of Shiro detects if the authenticator listens to logouts:
Authenticator authc = getAuthenticator();
if (authc instanceof LogoutAware) {
((LogoutAware) authc).onLogout(principals);
}
As the EnvironmentalRealmAuthenticator
is bound as a Tapestry service, it is initially injected as a proxy and hence authc instanceof LogoutAware
yields false
- that's why the default ModularRealmAuthenticator
is bound in a different way in the SecurityModule
of Tynamo:
// TYNAMO-155 It's not enough to identify ModularRealmAuthenticator by it's Authenticator interface only
// because Shiro tests if the object is an instanceof LogoutAware to call logout handlers
binder.bind(ModularRealmAuthenticator.class);
However, when I try to override my EnvironmentalRealmAuthenticator
that way
binder.bind(EnvironmentalRealmAuthenticator.class).withId("EnvironmentalRealmAuthenticator");
this results in the following exception:
Caused by: java.lang.IllegalStateException: Construction of service 'ServiceOverride' has failed due to recursion: the service depends on itself in some way. Please check org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at ServiceOverrideImpl.java:31) via org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder) (at TapestryIOCModule.java:52) for references to another service that is itself dependent on service 'ServiceOverride'.