vic*_*vic 6 spring-security spring-boot spring-java-config
我正在努力将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());
}
// ....
}
Run Code Online (Sandbox Code Playgroud)
当我点击主页URL时,我得到了Spring Security默认登录弹出面板.在我看来,上面的配置没有生效,但Spring Boot中的默认Spring Security配置却没有.如果是这样,如何覆盖默认值?
我找到了答案.我需要创建一个application.properties使用以下行调用的文件:
security.basic.enabled=false
Run Code Online (Sandbox Code Playgroud)
并将此文件放在src/main/resource.这就对了.
| 归档时间: |
|
| 查看次数: |
9308 次 |
| 最近记录: |