将Spring Security移至Java Config,authentication-success-handler-ref在哪里? [英] Moving Spring Security To Java Config, where does authentication-success-handler-ref go?
问题描述
我们的应用程序具有成功登录的自定义成功处理程序。它基本上将它们重定向到它们的会话到期时它们所在的页面。
Our app has a custom success handler for successful logins. It basically redirects them to the page they were on when their session expired.
我们正在转向Java配置而不是spring xml配置。配置的其余部分非常顺利,但是我们找不到将security:form-login标记的authentication-success-handler-ref属性放在哪里。
We're moving to a Java config rather than a spring xml config. The rest of the config went very smoothly, but we can't find where to put the authentication-success-handler-ref attribute of the security:form-login tag.
<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"/>
...
到目前为止,这是我们的配置。
Here's our config, so far.
@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放在哪里,但这肯定少了很重要。
Also, we can't find where to put default-target-url, but that is definitely less important.
警告,我们实际上使用的是Groovy,但代码与Java配置基本相同。
Caveat, we're actually using Groovy, but the code is basically the same as a Java config.
推荐答案
所有设置都可以在全局配置方法中完成。添加以下内容:
All settings can be done inside the global configure method. Add the following:
@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()
}
这篇关于将Spring Security移至Java Config,authentication-success-handler-ref在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!