SecurityContextHolder.getContext().getAuthentication() 返回 null
2022-09-02 22:12:27
我想使用以下代码手动绕过spring Security的用户:
User localeUser = new User();
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(localeUser ,null, localeUser .getAuthorities());
SecurityContext securityContext = SecurityContextHolder.getContext();
securityContext.setAuthentication(auth);
// Create a new session and add the security context.
HttpSession session = request.getSession(true);
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
return "dummyLogin";
虚拟登录页面(由磁贴处理)在内部调用同一控制器中的不同请求映射,我试图获取类似这样的身份验证。
SecurityContextHolder.getContext().getAuthentication()
我在哪里得到空?