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();
}
}

posted @ 2020-08-12 13:56  路要一步一步走  阅读(6132)  评论(0编辑  收藏  举报