我正在尝试使用Spring Security,所有人都使用一个角色.
我想根据ROLE重定向到2个不同的站点,但框架总是重定向到最后一个defaultSuccessUrl("/ ... ")**.这有可能吗?
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN")
.and().withUser("user").password("user").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/admin/**")
.access("hasRole('ROLE_ADMIN')").and().formLogin()
.defaultSuccessUrl("/admin**").loginPage("/")
.failureUrl("/").usernameParameter("username")
.passwordParameter("password").and().logout()
.logoutSuccessUrl("/").and()
.authorizeRequests().antMatchers("/user/**")
.access("hasRole('ROLE_USER')").and().formLogin()
.defaultSuccessUrl("/user**").loginPage("/")
.failureUrl("/").usernameParameter("username")
.passwordParameter("password").and().logout()
.logoutSuccessUrl("/");
http.csrf().disable();
}
}
Run Code Online (Sandbox Code Playgroud)