我们的应用有一个用于成功登录的自定义成功处理程序。它基本上将他们重定向到他们 session 到期时所在的页面。
我们正在转向 Java 配置而不是 spring xml 配置。配置的其余部分进行得非常顺利,但是我们找不到将 security:form-login 标记的 authentication-success-handler-ref 属性放在哪里。
<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 配置基本相同。
最佳答案
所有设置都可以在全局配置方法中完成。添加以下内容:
@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()
}
关于java - 将 Spring Security 移至 Java Config,authentication-success-handler-ref 去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21097528/