Spring Security and AOP
Is it possible开发者_JAVA技巧 to create a custom @Aspect and apply it to the Classes/Methods within Spring Security (3.0.3)?
I'm trying to do some logging of logon/logoff requests and none of my Advices are being triggered.
I'm using @AspectJ annotations and here is how I'm decorating my method:
@After("execution (* org.springframework.security.authentication.ProviderManager.doAuthentication(..))")
Rather use ApplicationListener
to catch the successful login. See the Javadocs for other event types.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;
@Component
public class AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> {
private static final Logger logger = LoggerFactory.getLogger(AuthenticationSuccessListener.class);
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent event) {
logger.debug("User {} logged in", event.getAuthentication().getName());
}
}
精彩评论