2010-08-09 8 views
1

맞춤 @Aspect를 생성하여 Spring Security (3.0.3)의 클래스/메소드에 적용 할 수 있습니까?스프링 보안 및 AOP

로그온/로그 오프 요청의 일부 로깅을하려고하는데 내 조언이 트리거되지 않습니다.

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

답변

2

가 오히려 성공적인 로그인을 잡으려고 ApplicationListener를 사용 : 내 방법을 장식하고있어 어떻게 여기에 주석을 @AspectJ 사용하고있어

이다. 다른 이벤트 유형은 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()); 
    } 
} 
+0

좋은 생각, 고마워! 그러나 나는 나의 Aspect가 제대로 작동하도록 할 수 있었지만 더 익숙해지기 위해 이것을 시도 할 것이다. –

+0

이것은 매력적입니다. –