E
E
Evgeny Krasnov2020-10-03 08:44:34
Google
Evgeny Krasnov, 2020-10-03 08:44:34

How to correctly pass reCAPTCHA through the FilterChain filter?

Greetings dear forum users.

I have such a task. I pass the reCAPTCHA

validation mechanism through the FilterChain filter and if false occurs , then it redirects back to the same “/login†page . Here's how I can properly tell the “/login†controller that the client failed the CAPTCHA check ?

package com.test;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class Test extends GenericFilterBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {


        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;




        httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/login");

            chain.doFilter(request, response);

    }

}


Or maybe I'm doing something wrong at all?

.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question