Wednesday, April 24, 2013

Spring Security - logging the Authentication Object Aspect

Spring Security - logging the user Aspect

here's one inspired by StackOverflow(

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;

public class AuthenticationManagerAspect {

 public void after(JoinPoint joinPoint,Object result) throws Throwable {
  System.out.println(">>> user: " + ((Authentication) result).getName());

No comments:

Post a Comment