1

カスタム@Aspectを作成し、それをSpring Security(3.0.3)内のクラス/メソッドに適用することは可能ですか?

ログオン/ログオフ要求のログを記録しようとしていますが、アドバイスがトリガーされていません。

私は@AspectJアノテーションを使用しており、これが私のメソッドをどのように装飾しているかを示しています。

@After("execution (* org.springframework.security.authentication.ProviderManager.doAuthentication(..))")
4

1 に答える 1

2

むしろApplicationListener、成功したログインをキャッチするために使用します。他のイベントタイプについては、 Javadocを参照してください。

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());
    }
}
于 2010-08-09T08:53:36.380 に答える