Last active
December 24, 2015 15:49
-
-
Save dannyduc/6823614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AuthenticationUtil { | |
public static String getUserName() { | |
if (isAnonymous()) { | |
return "anonymous"; | |
} | |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | |
return authentication == null ? null : authentication.getName(); | |
} | |
public static boolean isAnonymous() { | |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | |
boolean isAnonymous = AnonymousAuthenticationToken.class.isAssignableFrom(authentication.getClass()); | |
return isAnonymous; | |
} | |
public static boolean isAuthenticated() { | |
return UserContext.getUserDetails() != null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment