class AuthenticationTokenFilter extends BasicAuthenticationFilter {

    private RedisTemplate redisTemplate;
    private AuthIgnoreConfig authIgnoreConfig;
    private ObjectMapper objectMapper = new ObjectMapper();

    public AuthenticationTokenFilter(AuthenticationManager authenticationManager, AuthIgnoreConfig authIgnoreConfig,RedisTemplate template) {
        super(authenticationManager);
        this.redisTemplate = template;
        this.authIgnoreConfig = authIgnoreConfig;
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {<FILL_FUNCTION_BODY>}


    @SneakyThrows
    public void writer(HttpServletResponse response, String msg) {
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(objectMapper.writeValueAsString(R.error(HttpServletResponse.SC_UNAUTHORIZED, msg)));
    }
}

        String token = request.getHeader(Constant.TOKEN);
        if (StrUtil.isBlank(token) || StrUtil.equals(token, "null")) {
            token = request.getParameter(Constant.TOKEN);
        }

        if (StrUtil.isNotBlank(token) && !StrUtil.equals(token, "null")) {
            final String requestURI = request.getRequestURI();
            if(!authIgnoreConfig.isContains(requestURI)){
                Object userInfo = redisTemplate.opsForValue().get(Constant.AUTHENTICATION_TOKEN + token);
                if (ObjectUtil.isNull(userInfo)) {
                    writer(response, "无效token");
                    return;
                }
                String user[] = userInfo.toString().split(",");
                if (user == null || user.length != 2) {
                    writer(response, "无效token");
                    return;
                }

                String userId = user[0];
                CustomUserDetailsService customUserDetailsService = SpringContextUtils.getBean(CustomUserDetailsService.class);
                UserDetails userDetails = customUserDetailsService.loadUserByUserId(userId);
                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
                authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
        }
        chain.doFilter(request, response);
    
<methods>public void <init>(org.springframework.security.authentication.AuthenticationManager) ,public void <init>(org.springframework.security.authentication.AuthenticationManager, org.springframework.security.web.AuthenticationEntryPoint) ,public void afterPropertiesSet() ,public void setAuthenticationDetailsSource(AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?>) ,public void setCredentialsCharset(java.lang.String) ,public void setRememberMeServices(org.springframework.security.web.authentication.RememberMeServices) ,public void setSecurityContextRepository(org.springframework.security.web.context.SecurityContextRepository) <variables>private org.springframework.security.web.authentication.www.BasicAuthenticationConverter authenticationConverter,private org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint,private org.springframework.security.authentication.AuthenticationManager authenticationManager,private java.lang.String credentialsCharset,private boolean ignoreFailure,private org.springframework.security.web.authentication.RememberMeServices rememberMeServices,private org.springframework.security.web.context.SecurityContextRepository securityContextRepository