3
我試圖使自定義AuthenticationProcessingFilter成功登錄添加自定義過濾器
這裏後,在會議上,一些用戶數據保存的我的過濾器:
package projects.internal;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.Authentication;
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
public class MyAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
protected void onSuccessfulAuthentication(HttpServletRequest request,
HttpServletResponse response, Authentication authResult)
throws IOException {
super.onSuccessfulAuthentication(request, response, authResult);
request.getSession().setAttribute("myValue", "My value is set");
}
}
,這裏是我的security.xml文件
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security pre-post-annotations="enabled">
</global-method-security>
<http use-expressions="true" auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/images/**" filters="none" />
<intercept-url pattern="/scripts/**" filters="none" />
<intercept-url pattern="/styles/**" filters="none" />
<intercept-url pattern="/p/login.jsp" filters="none" />
<intercept-url pattern="/p/register" filters="none" />
<intercept-url pattern="/p/**" access="isAuthenticated()" />
<form-login
login-processing-url="/j_spring_security_check"
login-page="/p/login.jsp"
authentication-failure-url="/p/login_error.jsp" />
<logout />
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"/>
</authentication-provider>
</authentication-manager>
<beans:bean id="authenticationProcessingFilter" class="projects.internal.MyAuthenticationProcessingFilter">
<custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
</beans:bean>
<beans:bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">
</beans:bean>
</beans:beans>
它給這裏的錯誤:
<custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
CVC-attribute.3 CVC-複雜type.4 CVC-枚舉vaild
是什麼問題:
在這條線找到多個註釋?
放在你確定名稱爲「authenticationProcessingFilter」尚未採取默認的Spring Security豆? – Gandalf 2010-03-23 20:08:13
有一個更好的工具可以滿足你的需要:'authentication-success-handler' - 把它加到你的'