SyntaxHighlighter

Wednesday, April 24, 2013

Spring Security - logging the Authentication Object Aspect

Spring Security - logging the user Aspect

here's one inspired by StackOverflow(http://stackoverflow.com/questions/16186087/capture-successful-login-with-aspectj-and-spring-security/16187405)

to log the results of an authenticationManagers.authenticate when using in a web context, you need to use CGLIB.  here's an example;

here's the XML



 
  
 
 
 
  
   
    
   
  
 

 

 



and here's the aspect

package de.incompleteco.spring.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.security.core.Authentication;

@Aspect
public class AuthenticationManagerAspect {

 @AfterReturning(pointcut="execution(* org.springframework.security.authentication.AuthenticationManager.authenticate(..))"
   ,returning="result")
 public void after(JoinPoint joinPoint,Object result) throws Throwable {
  System.out.println(">>> user: " + ((Authentication) result).getName());
 }
 
}


No comments:

Post a Comment