spring security 获取当前登录用户

public class SpringSecurityUtil {

    //session 由controller 注入参数传入
    public static String currentUser(HttpSession session) {
        SecurityContextImpl securityContext = (SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT");
        return ((UserDetails)securityContext.getAuthentication().getPrincipal()).getUsername();
    }
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页