我们的应用程序有一个自定义的成功处理程序,用于成功登录。当他们的会话到期时,它基本上将他们重定向到他们所在的页面。
我们将转向Java配置,而不是spring xml配置。配置的其余部分进行得非常顺利,但是我们找不到将security:form-login标记的身份验证-成功-处理程序-引用属性放在哪里。
<security:http auto-config='true'>
...
<security:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY"/>
<security:form-login login-page="/login" default-target-url="/sites"
authentication-failure-url="/login"
authentication-success-handler-ref="authenticationSuccessHandler"/>
...
到目前为止,这是我们的配置。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login")
.and()
.logout()
.permitAll()
.and()
}
此外,我们找不到将default-target-url放在哪里,但这绝对不那么重要。
注意,我们实际上使用的是Groovy,但代码基本上与Java配置相同。
发布于 2014-01-14 04:11:42
所有设置都可以在全局配置方法中完成。添加以下内容:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/sites")
.failureUrl("/login")
.successHandler(yourSuccessHandlerBean) // autowired or defined below
.and()
.logout()
.permitAll()
.and()
}
发布于 2014-01-14 02:03:31
您必须创建扩展SimpleUrlAuthenticationSuccessHandler
或SavedRequestAwareAuthenticationSuccessHandler
的bean。例如:
@Bean
public SavedRequestAwareAuthenticationSuccessHandler successHandler() {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("/secure/");
return successHandler;
}
然后,您必须在扩展AbstractAuthenticationProcessingFilter
的bean上设置它
UsernamePasswordAuthenticationFilter authenticationFilter = new UsernamePasswordAuthenticationFilter();
authenticationFilter.setAuthenticationSuccessHandler(successHandler());
https://stackoverflow.com/questions/21097528
复制相似问题