I use a SecurityContextHolder and a custom UserDetailsService to get UserDetails from a SecurityContextHolder :
Object o = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserDetailsDTO user = (UserDetailsDTO) o;
I left zero checks, etc., but this is an idea. I use this in pointcut @Around for @Aspect :
@Around("execution(* user.service.*.*(..))") public Object audit(ProceedingJoinPoint call) throws Throwable {
Looking at the SecurityContextHolder class, it uses ThreadLocal by default, but the pointcut stuff also seems to have some kind of encapsulated thread logic.
Is it possible that a user conflict could arise (i.e., gain UserA access from one session for a UserB audit event in another concurrent session), or possibly a null user.
Is there a better way to get user credentials / profile?
java spring spring-mvc spring-security
Droo
source share