gpt4 book ai didi

java - 禁用 Spring Security 基本登录 - Spring REST Web 服务

转载 作者:行者123 更新时间:2023-11-29 05:23:50 26 4
gpt4 key购买 nike

在我的 SecurityConfig.java 中,

    @Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password")
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").hasRole("USER")
.anyRequest().anonymous().and().httpBasic();
}

我如何完全禁用 Spring Security,从而无需输入“用户”和“密码”即可访问我的 Web 服务?

最佳答案

使用这个 Spring Security 配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}

请注意,这不会在请求链中禁用 Spring Security,它只是告诉 Spring Security 允许所有请求

关于java - 禁用 Spring Security 基本登录 - Spring REST Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23520561/

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