gpt4 book ai didi

spring-security - Spring Boot 中的 Spring Security 配置

转载 作者:行者123 更新时间:2023-12-04 14:13:36 24 4
gpt4 key购买 nike

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

最佳答案

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

security.basic.enabled=false

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

关于spring-security - Spring Boot 中的 Spring Security 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21171265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com