开发者

Spring Security and AOP

开发者 https://www.devze.com 2023-01-10 14:02 出处:网络
Is it possible开发者_JAVA技巧 to create a custom @Aspect and apply it to the Classes/Methods within Spring Security (3.0.3)?

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());
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消