private String getUserName() {import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails;
Object principal = SecurityContextHolder
.getContext()
.getAuthentication()
.getPrincipal();
String userName;
if (principal instanceof UserDetails) {
userName = ((UserDetails)principal).getUsername();
} else {
userName = principal.toString();
}
return userName;
}
Keine Kommentare:
Kommentar veröffentlichen