Last active
December 16, 2015 07:09
-
-
Save JohnathanMarkSmith/5396622 to your computer and use it in GitHub Desktop.
Look up user in Spring
This file contains 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
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