在Java Spring Web应用程序中,WebSecurityConfigurerAdapter
类已扩展,configure(HttpSecurity http)
用于设置authorizeRequests()
,formLogin()
等。
/>
是否可以在configure(HttpSecurity http)
中指定多个登录页面?
(我不想知道是否可以使用XML(POM)等,但在配置函数中。)
例如,最终结果如下:
/admin/something
会将您带到/admin/
并强制您登录管理页面。/user/something
会将您带到/user/
并强制您登录用户页面。loginProcessingUrl
等答案 0 :(得分:0)
可以做到。在SecurityConfig
类中使用@Order
注释并声明扩展WebSecurityConfigurerAdapter
的多个类:
@Order(1)
@Configuration
public static class FirstConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception { /* Settings for login page 1 here. */ }
}
@Order(2)
@Configuration
public static class SecondConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception { /* Settings for login page 2 here. */ }
}
//And 3, and so on.
然后,在相应的configure
方法中,只需像往常一样使用formLogin()
等设置相应的网页。