Spring Security:工具类

public class SecurityUtils{

    public static Authentication getActiveAuthentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 获取当前用户
     */
    public static User getActiveUser() {
        return (User) getActiveAuthentication().getPrincipal();
    }

    public static String getActiveAccount(){
        return getActiveUser().getUsername();
    }
}
原文地址:https://www.cnblogs.com/wwjj4811/p/13767908.html