对于多登陆页在网上查找了很多资料,但由于项目中的所有配置已经不使用xml方式了,因此,网上的很多方法都不试用了。
最后,还是在spring security的文档中找到了解决方法。在配置文件中,配置多个配置实现。
记录如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
   | @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class MultiHttpSecurityConfiguration {     @Autowired     public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {         auth                 .inMemoryAuthentication()                 .withUser("admin").password("123456").roles("USER");     }     @Configuration     @Order(1)     public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {         @Override         protected void configure(HttpSecurity http) throws Exception {             http.antMatcher("/user/**")                     .authorizeRequests().anyRequest().authenticated()                     .and()                     .formLogin().loginPage("/user/login").permitAll().and()                     .logout()                     .clearAuthentication(true)                     .logoutSuccessUrl("/user/index")                      .invalidateHttpSession(true);;         }     }     @Configuration     public static class AppLoginSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {         protected void configure(HttpSecurity http) throws Exception {             http.antMatcher("/app/**")                     .authorizeRequests().anyRequest().authenticated()                     .and()                     .formLogin().loginPage("/app/login").permitAll().and()                     .logout()                     .clearAuthentication(true)                     .logoutSuccessUrl("/app/index")                      .invalidateHttpSession(true);         }     } }
   |