class ValidateCodeFilter extends OncePerRequestFilter {

    private AntPathMatcher pathMatcher = new AntPathMatcher();
    private RedisTemplate redisTemplate;
    private AuthenticationFailureHandler authenticationFailureHandler;

    public ValidateCodeFilter(RedisTemplate redisTemplate, AuthenticationFailureHandler authenticationFailureHandler){
        this.redisTemplate = redisTemplate;
        this.authenticationFailureHandler = authenticationFailureHandler;
    }

    @SneakyThrows
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) {<FILL_FUNCTION_BODY>}
}

        String url = request.getRequestURI();
        if (pathMatcher.match(Constant.TOKEN_ENTRY_POINT_URL,url)){
            String captcha = request.getParameter("captcha");
            String randomStr = request.getParameter("randomStr");

            if(StrUtil.isBlank(captcha) || StrUtil.isBlank(randomStr)){
                CustomAuthenticationException exception = new CustomAuthenticationException("验证码为空");
                authenticationFailureHandler.onAuthenticationFailure(request,response,exception);
                return;
            }

            String code_key = (String) redisTemplate.opsForValue().get(Constant.NUMBER_CODE_KEY + randomStr);
            if(StrUtil.isEmpty(code_key)){
                CustomAuthenticationException exception = new CustomAuthenticationException("验证码过期");
                authenticationFailureHandler.onAuthenticationFailure(request,response,exception);
                return;
            }

            if(!captcha.equalsIgnoreCase(code_key)){
                CustomAuthenticationException exception = new CustomAuthenticationException("验证码不正确");
                authenticationFailureHandler.onAuthenticationFailure(request,response,exception);
                return;
            }
        }
        filterChain.doFilter(request,response);
    
<methods>public void <init>() ,public final void doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) throws javax.servlet.ServletException, java.io.IOException<variables>public static final java.lang.String ALREADY_FILTERED_SUFFIX