Можно ли создать собственный @Aspect и применить его к классам/методам в Spring Security (3.0.3)?
Я пытаюсь вести журнал запросов на вход/выход из системы, и ни один из моих советов не срабатывает.
Я использую аннотации @AspectJ, и вот как я украшаю свой метод:
@After("execution (* org.springframework.security.authentication.ProviderManager.doAuthentication(..))")
Ответ 1 · рейтинг 2 · hleinone
Вместо этого используйте ApplicationListener, чтобы поймать успешный вход в систему. См. Javadocs для других типов событий.
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());
}
}