|
@@ -31,12 +31,18 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
|
|
throws ServletException, IOException
|
|
|
{
|
|
|
+ //通过令牌服务获取登录用户信息
|
|
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
+ //1 判断是否登录,2 判断当前是否存在认证过的对象
|
|
|
if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
|
|
|
{
|
|
|
+ //验证令牌是否过期
|
|
|
tokenService.verifyToken(loginUser);
|
|
|
+ //创建认证对象
|
|
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
+ //设置认证对象的详细信息
|
|
|
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
+ //设置对象到上下文中,其他地方也可以访问用户信息
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
}
|
|
|
chain.doFilter(request, response);
|