2

我正在尝试添加另一个名为 captcha 验证过滤器的过滤器以及 spring security 的身份验证过滤器。我收到这个错误。我错过了什么?bean初始化失败;嵌套异常是 org.springframework.beans.ConversionNotSupportedException:无法将类型“java.util.LinkedHashMap”的属性值转换为属性“filterChainMap”所需的类型“java.util.Map”;嵌套异常是 java.lang.IllegalStateException:无法将类型 [com.asu.edu.base.vo.CaptchaFilterVO] 的值转换为属性“filterChainMap[/**][3]”所需的类型 [javax.servlet.Filter] : 没有找到匹配的编辑器或转换策略

我的 .java 文件

public class CaptchaFilterVO {
    @Autowired
    private ReCaptcha reCaptcha = null;

    public void doFilterInternal(HttpServletRequest req, HttpServletResponse res,
            FilterChain chain) throws IOException, ServletException {       
        String recaptcha_response = req.getParameter("recaptcha_response_field");
        String recaptcha_challenge = req.getParameter("recaptcha_challenge_field");
        String remoteAddress = req.getRemoteAddr();
        ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer(
                remoteAddress, recaptcha_challenge, recaptcha_response);
        if (!reCaptchaResponse.isValid()) {

            System.out.println("Captcha worong. Please try again.");        

        } 
        else 
        {
            System.out.println("Captcha correct. No need to try again.");
        }
        chain.doFilter(req, res);
    }
}

springsecurity.xml

     <http auto-config="true">
        <!-- intercept-url pattern="/welcome*" access="ROLE_DEPARTMENT_MGR,ROLE_REGULAR_EMP,ROLE_GUEST_USR,ROLE_CORPORATE_MGR" />
        <intercept-url pattern="/admin*" access="ROLE_ADMIN" /-->
        <intercept-url pattern="/login" filters="none" />
        <intercept-url pattern="/resources*" filters="none" />
        <intercept-url pattern="/register" filters="none" />
        <intercept-url pattern="/logout" filters="none" />
        <intercept-url pattern="/loginfailed" filters="none" />
        <intercept-url pattern="/admin*" access="ROLE_ADMIN" />
        <intercept-url pattern="/Dashboard*" access="ROLE_DEPARTMENT_MGR,ROLE_REGULAR_EMP,ROLE_CORPORATE_MGR" />
        <intercept-url pattern="/*" access="IS_AUTHENTICATED_FULLY"/>
        <form-login login-page="/login" default-target-url="/"
            authentication-failure-url="/loginfailed"   />
        <logout logout-success-url="/logout" />
        <custom-filter ref="captchaVerifierFilter" after="FORM_LOGIN_FILTER"/>

</http>     
 <beans:bean id="captchaVerifierFilter" class="com.asu.edu.base.vo.CaptchaFilterVO"/>
 <beans:bean id="springSecurityFilterChain" class="org.springframework.web.filter.DelegatingFilterProxy"/>
<beans:bean id="myfilterChainProxy" class="org.springframework.security.web.FilterChainProxy">
    <filter-chain-map path-type="ant">     
         <filter-chain pattern="/*" filters="springSecurityFilterChain,captchaVerifierFilter"/>
    </filter-chain-map>
 </beans:bean>

编辑:公共类 CaptchaFilterVO 扩展 OncePerRequestFilter 实现 javax.servlet.Filter 现在我扩展了 OncePerRequestFilter 类,但现在我面临崩溃。请提供任何帮助。org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 bean 类 [org.springframework.http.HttpRequest]:指定类是接口 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894) org .springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org .springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.

4

2 回答 2

1

您的CaptchaFilterVO过滤器应该实现javax.servlet.Filter.

于 2012-11-07T09:16:43.030 回答
1

您的方法名称 ( doFilterInternal) 表明您想要扩展org.springframework.web.filter.OncePerRequestFilter

添加:

extends OncePerRequestFilter

在你的班级名称之后。

OncePerRequestFilter实现javax.servlet.Filter

和...

Filter base class that guarantees to be just executed once per request,
on any servlet container. It provides a doFilterInternal
method with HttpServletRequest and HttpServletResponse arguments.
于 2012-11-07T09:28:25.130 回答