| | |
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
|
| | | {
|
| | | public class JwtAuthenticationTokenFilter extends OncePerRequestFilter |
| | | { |
| | | @Autowired
|
| | | private TokenService tokenService;
|
| | |
|
| | | @Override
|
| | | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
| | | throws ServletException, IOException
|
| | | {
|
| | | LoginUser loginUser = tokenService.getLoginUser(request);
|
| | | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| | | throws ServletException, IOException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | 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);
|
| | | }
|
| | | }
|
| | | } |
| | | chain.doFilter(request, response); |
| | | } |
| | | |
| | | @Override |
| | | protected boolean shouldNotFilterAsyncDispatch() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | protected boolean shouldNotFilterErrorDispatch() |
| | | { |
| | | return false; |
| | | } |
| | | } |