我試圖添加另一個名爲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]' :不匹配編輯或轉換戰略發現在spring security 3.0中添加自定義過濾器
我的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 現在我有擴展OncePerReque stFilter類,但現在我面臨崩潰。請任何幫助。 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.java:368) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) 組織。 springframework.security.web.access.intercept.FilterSecurityInterce ptor.doFilter(FilterSecurityInterceptor.java:83) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
'無法實例化bean類[org.springframework.http.HttpRequest]:指定類是interface.'您可能創建的接口的豆。這是不允許的,因爲接口不能被實例化。去掉它。 –
我還沒有爲HttpRequest創建bean。我只創建類型爲以下bean: 從上面的代碼可以看到,CaptchaFilterVO是一個class –
PhantomM
提供有關何時引發此異常的更多信息。 –