Skip to content

Instantly share code, notes, and snippets.

@JohnathanMarkSmith
Last active December 16, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnathanMarkSmith/5396622 to your computer and use it in GitHub Desktop.
Save JohnathanMarkSmith/5396622 to your computer and use it in GitHub Desktop.
Look up user in Spring
protected String getUser() {
String username;
LOGGER.debug("getAuthentication().getName():"
+ SecurityContextHolder.getContext().getAuthentication()
.getName());
Object obj = SecurityContextHolder.getContext().getAuthentication()
.getPrincipal();
if (obj instanceof UserDetails) {
username = ((UserDetails) obj).getUsername();
} else {
username = obj.toString();
}
LOGGER.debug("getUser:" + username);
return username;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment