我有两个WebSecurityConfigureAdapter,每个都有自己的过滤链(两个登录页面)。应该设置successForwardUrl是不同的,所以我在每个过滤器链中都指定了一个。
问题是优先级最低的WebSecurityConfigureAdapter的successForwardUrl会覆盖另一个。因此,成功总是归功于“ / users / main”。
(事实证明,logoutSuccessUrl也是如此)
WebSecurityConfigureAdapter类如下:
@Order(1)
@Configuration
public class CustomerSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/customers/**")
.authorizeRequests()
.anyRequest().hasRole("CUSTOMER")
.and()
.formLogin()
.loginPage("/login2")
.successForwardUrl("/customers/main")
.permitAll()
.and()
.logout().logoutSuccessUrl("/")
.permitAll();
}
}
@Configuration
public class UserSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index.html").permitAll()
.antMatchers("/users/**").hasAnyRole("USER", "ADMIN")
.and()
.formLogin()
.loginPage("/login")
.successForwardUrl("/users/main")
.permitAll()
.and()
.logout().logoutSuccessUrl("/").permitAll();
}
}