Skip to content

Instantly share code, notes, and snippets.

@dannyduc
Last active December 24, 2015 15:49
Show Gist options
  • Save dannyduc/6823614 to your computer and use it in GitHub Desktop.
Save dannyduc/6823614 to your computer and use it in GitHub Desktop.
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