If you want to get current logged in user, use the code snippet below:

        User currentUser = null;
        SecurityContext ctx = SecurityContextHolder.getContext();
        if (ctx.getAuthentication() != null) {
            Authentication auth = ctx.getAuthentication();
            if (auth.getPrincipal() instanceof UserDetails) {
                currentUser = (User) auth.getPrincipal();
            } else if (auth.getDetails() instanceof UserDetails) {
                currentUser = (User) auth.getDetails();
            } else {
                throw new AccessDeniedException("User not properly
authenticated.");
            }
        }

Ali Behzadian Nejad.

-- 
View this message in context: 
http://www.nabble.com/How-to-get-user-from-session-tp18216209s2369p18238909.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to