Spring security 在spring security中添加自定义过滤器
我正在尝试创建自定义AuthenticationProcessingFilter,以便在成功登录后在会话中保存一些用户数据 这是我的过滤器:Spring security 在spring security中添加自定义过滤器,spring-security,Spring Security,我正在尝试创建自定义AuthenticationProcessingFilter,以便在成功登录后在会话中保存一些用户数据 这是我的过滤器: package projects.internal; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.s
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属性。3
cvc复合型
cvc枚举有效
问题是什么?我认为在SpringSecurity3.0模式中,这不是一个有效的过滤器位置。退房我再也看不到它的列表了。也许可以尝试
BASIC\u AUTH\u FILTER
不是有效的筛选器别名,您应该使用AUTHENTICATION\u PROCESSING\u FILTER
李>FORM\u LOGIN\u FILTER
应该放在
身份验证成功处理程序
-将它添加到您的
,我认为它比filter更合适。