将 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屋!