@EnableWebSecurity
public class MultiHttpSecurityConfig {
@Configuration
@Order(1)
public static class App1ConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/my/**", "/account/**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')")
.and().formLogin().loginPage("/login");
}
}
@Configuration
@Order(2)
public static class App2ConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.and().formLogin().loginPage("/adminlogin");
}
}
}
Dies soll zwei verschiedene Login-Formen sein. Mein Problem ist, dass der mit der höchsten Ordnung/Adminlogin nicht angezeigt wird. Ich habe eine Idee warum? Bitte helfen Sie. Der Code ist von Spring boot - how to configure multiple login pages?Spring Boot und Feder Sicherheit mehrere Login-Seiten
Sofia Vorschlag folgend ich das versucht:
@Configuration
@Order(2)
public static class UserConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatcher(new AntPathRequestMatcher("/my/**"))
.csrf().disable()
.authorizeRequests().antMatchers("/my/**").access("hasRole('ROLE_USER')")
.and().formLogin().loginPage("/login");
}
}
@Configuration
@Order(1)
public static class AdminConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatcher(new AntPathRequestMatcher("/admin/**"))
.csrf().disable()
.authorizeRequests().antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.and().formLogin().loginPage("/adminlogin");
}
}
Aber in beiden Fällen/login genannt wird
Wenn ich geben Sie das Beispiel in http://docs.spring.io/spring- Sicherheit/site/docs/current/Verweis/html/jc.html # multiple-httpsecurity Ich bekomme diese Ausnahme: java.lang.IllegalStateException: @Order on WebSecurityConfigurers muss eindeutig sein. Order of 100 wurde bereits auf ... FormLoginWebSecurityConfigurerAdapter ... – ropo