小编典典

Spring Boot中的Spring安全配置

spring-boot

我正在将 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 配置没有生效。如果是这样,如何覆盖默认值? __


阅读 419

收藏
2020-05-30

共1个答案

小编典典

我找到了答案。我需要创建一个application.properties带有以下行的文件:

security.basic.enabled=false

并将此文件放在下src/main/resource。这就对了。

2020-05-30