other thing
Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
parent
1ab1a4ad8a
commit
8966f306df
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
package cyou.chenx221.helper;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class UsernameHelper {
|
||||
public UsernameHelper() {
|
||||
}
|
||||
|
||||
// 获取当前登录的用户名
|
||||
public String getCurrentUsername() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails) {
|
||||
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
|
||||
return userDetails.getUsername();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user