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