public static AuditorAware < String > auditorProvider ( ATUser systemUser , ATUser anonymousUser ) { return new AuditorAware < String > ( ) { private final Log LOGGER = LogFactory . getLog ( AuditorAware . class ) ; public String getCurrentAuditor ( ) { SecurityContext secCtx = SecurityContextHolder . getContext ( ) ; if ( null == secCtx ) { return systemUser . getUsername ( ) ; } Authentication authentication = secCtx . getAuthentication ( ) ; if ( authentication == null || ! authentication . isAuthenticated ( ) ) { LOGGER . debug ( String . format ( "using %s user for auditing" , systemUser . getUsername ( ) ) ) ; return systemUser . getUsername ( ) ; } else if ( authentication . isAuthenticated ( ) && ! ATUser . class . isAssignableFrom ( authentication . getPrincipal ( ) . getClass ( ) ) ) { LOGGER . debug ( String . format ( "using %s user for auditing" , anonymousUser . getUsername ( ) ) ) ; return anonymousUser . getUsername ( ) ; } return ( ( ATUser ) authentication . getPrincipal ( ) ) . getUsername ( ) ; } } ; }
creates a auditor provider