1
我想配置一個基於Java的春季安全重定向到未經過身份驗證的任何請求登錄頁面,目前有以下配置:春季安全重定向到登錄表單與基於Java的配置
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity security) throws Exception {
security
.ignoring()
.antMatchers("/resources/**")
;
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.formLogin()
.loginPage("/login").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
;
}
}
在實現WebApplicationInitializer
我有以下類:
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(SecurityConfig.class);
container.addListener(new ContextLoaderListener(rootContext));
的configure(HttpSecurity httpSecurity)
方法中設置一個斷點表明,該方法被調用在啓動時,但沒有請求重定向到/login
。