【发布时间】:2014-02-05 22:04:19
【问题描述】:
我正在将 Spring 3 项目转换为 Spring 4 + Spring Boot。我不知道这样做是否正确。我将 Spring Security XML 配置转换为 基于 Java 的配置,如下所示:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/home").permitAll()
.anyRequest().authenticated();
http.formLogin()
.defaultSuccessUrl("/afterLogin")
.loginPage("/profiles/lognin/form")
.failureUrl("/accessDenied")
.and()
.authorizeRequests()
.regexMatchers("....")
.hasRole("ROLE_USER")
.antMatchers("....")
.hasRole("ROLE_USER")
//....
;
}
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder)
throws Exception {
authManagerBuilder.authenticationProvider(this.getDaoAuthenticationProvider());
}
// ....
}
当我点击主页 URL 时,我得到 Spring Security 默认登录弹出面板。在我看来,上面的配置没有生效,但是Spring Boot中默认的Spring Security配置没有生效。如果是这样,如何覆盖默认的?
【问题讨论】:
标签: spring-security spring-boot spring-java-config