getPrincipal()与getName()的区别
程序员文章站
2022-06-22 23:51:08
...
public String getCurrentUsername() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
return ((UserDetails) principal).getUsername();
}
if (principal instanceof Principal) {
return ((Principal) principal).getName();
}
return String.valueOf(principal);
}
public String getCurrentUsername() {
return SecurityContextHolder.getContext().getAuthentication().getName();
}