我在我的客户端项目中有这个来获取远程配置:
@PropertySource(value = "http://user:xxx@localhost:8888/ConfigRepo/dev/main/db/database.properties", ignoreResourceNotFound = true)
url
http://user:xxx@localhost:8888/ConfigRepo/dev/main/db/database.properties
由Spring Cloud Config Service提供,受Spring Security保护。我的 Spring 云配置服务项目中有这个配置:
spring:
security:
user:
name: user
password: xxx
和Spring安全配置:
@Configuration
public class ServiceConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/ConfigRepo").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
return http.build();
}
}
现在,如果我运行命令
curl http://user:xxx@localhost:8888/ConfigRepo/dev/main/db/database.properties
,它将正确返回属性。但是上面的@PropertySource
会显示这个错误信息:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://user:xxx@localhost:8888/ConfigRepo/dev/main/db/database.properties
我想知道如何让 Spring security 接受来自
@PropertySource
的基本身份验证?或者任何其他等效注释允许我实现这个?