gpt4 book ai didi

java - 当 Spring Security 在 Spring Cloud Config Server 上处于 Activity 状态时,Spring Cloud Config Client 未获取配置

转载 作者:行者123 更新时间:2023-12-04 02:38:53 24 4
gpt4 key购买 nike

当我在没有 spring security 的情况下运行 spring cloud config server 时,服务会毫无问题地获取配置,但是当我激活 Spring security 时,它不会获取配置文件。它似乎引发了 401 http 错误。我检查了用户名和密码是否正确,我也尝试了 user:password@url 的身份验证方式与相同的问题。

如果我直接在浏览器中访问 url http://localhost:8888/service/default 并输入用户名和密码,则会显示配置。

任何帮助将不胜感激,我不确定我的云配置或安全配置是否存在问题。

Spring Boot 版本:'2.2.4.RELEASE'
spring-cloud-config-server 版本:'2.2.1.RELEASE'
构建系统:Gradle
Java 8

这个配置总是失败,我尝试将它添加到现有的服务中,但它没有工作,所以我通过 https://start.spring.io/ 上的 spring 初始化程序创建了一个新的配置服务器和一个新的客户端使用以下配置,仍然无法正常工作。

安全激活时记录:

2020-02-19 14:29:16.553  INFO 14996 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-02-19 14:29:16.577 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate : HTTP GET http://localhost:8888/service/default
2020-02-19 14:29:16.634 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2020-02-19 14:29:16.647 DEBUG 14996 --- [ main] o.s.web.client.RestTemplate : Response 401 UNAUTHORIZED
2020-02-19 14:29:16.652 WARN 14996 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 401 : [{"timestamp":"2020-02-19T12:29:16.642+0000","status":401,"error":"Unauthorized","message":"Unauthorized","path":"/service/default"}]

安全性被禁用/全部允许时记录

2020-02-19 12:43:13.756  INFO 4972 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-02-19 12:43:17.563 INFO 4972 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=service, profiles=[default], label=null, version=fb9ccb6e46098bfe425130d6447a0797206e5c2f, state=null

配置服务器 application.yml 文件
github uri 被隐藏了,连接到私有(private) repo 不是问题。

server:
port: 8888

spring:
application:
name: config-server
security:
user:
name: 'root'
password: '1234'
cloud:
config:
server:
git:
uri: <github-uri>
ignore-local-ssh-settings: false
strict-host-key-checking: false
private-key: 'classpath:resources/id_rsa'

服务应用程序.yml 文件

spring:
application:
name: service
cloud:
config:
uri: http://localhost:8888
username: 'root'
password: '1234'
fail-fast: true

网络安全非常基础,但以下是安全配置:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

// Secure the endpoints with HTTP Basic authentication
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").fullyAuthenticated();
http.httpBasic().and().exceptionHandling();
}
}

最佳答案

对于所有正在关注任何过时的云教程的人:- 从 springboot 2.4 开始,必须添加 bootstrap starter 依赖项,以便按照教程使用 bootstrap.properties (bootstrap.yml) 进行外部配置。

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

关于java - 当 Spring Security 在 Spring Cloud Config Server 上处于 Activity 状态时,Spring Cloud Config Client 未获取配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60298657/

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