Closed nevermore75 closed 4 years ago
hi macro:
在过滤器 JwtAuthenticationTokenFilter的逻辑中,
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) { UserDetails userDetails = this.userDetailsService.loadUserByUsername(username); if (jwtTokenUtil.validateToken(authToken, userDetails)) { UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); LOGGER.info("authenticated user:{}", username); SecurityContextHolder.getContext().setAuthentication(authentication); } }
已经set 了Authentication,但debug时发现SecurityContextHolder.getContext().getAuthentication() 总是为 null。 网上查找资料有看到: 在过滤链执行完时org.springframework.security.web.context.SecurityContextPersistenceFilter类会 调用SecurityContextHolder.clearContext();而把SecurityContextHolder清空,所以会得到null。 有什么合适的解决方法么
hi macro:
在过滤器 JwtAuthenticationTokenFilter的逻辑中,
已经set 了Authentication,但debug时发现SecurityContextHolder.getContext().getAuthentication() 总是为 null。 网上查找资料有看到: 在过滤链执行完时org.springframework.security.web.context.SecurityContextPersistenceFilter类会 调用SecurityContextHolder.clearContext();而把SecurityContextHolder清空,所以会得到null。 有什么合适的解决方法么