我正在尝试从 Feign 客户端应用程序调用一些由 client_credentials 授权类型保护的后端系统。
可以使用以下 curl 结构检索来自后端系统的访问令牌(仅作为示例):
curl --location --request POST '[SERVER URL]/oauth/grant' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: WebSessionID=172.22.72.1.1558614080219404; b8d49fdc74b7190aacd4ac9b22e85db8=2f0e4c4dbf6d4269fd3349f61c151223' \
--data-raw 'grant_type=client_credentials' \
--data-raw 'client_id=[CLIENT_ID]' \
--data-raw 'client_secret=[CLIENT_SECRET]'
{"accessToken":"V29C90D1917528E9C29795EF52EC2462D091F9DC106FAFD829D0FA537B78147E20","tokenType":"Bearer","expiresSeconds":7200}
Run Code Online (Sandbox Code Playgroud)
然后应将此 accessToken 设置在标头中,以用于对后端系统的后续业务调用。
所以现在我的问题是,如何使用 Feign 和 Spring Boot Security 5 来实现这一点。 经过一些研究,我找到了这个解决方案(不起作用):
spring:
security:
oauth2:
client:
registration:
backend:
client-id:[CLIENT_ID]
client-secret: [CLIENT_SECRET]
authorization-grant-type: client_credentials
provider:
backend:
token-uri: [SERVER URL]/oauth/grant
Run Code Online (Sandbox Code Playgroud)
curl --location --request POST '[SERVER URL]/oauth/grant' \
--header 'Content-Type: application/x-www-form-urlencoded' …Run Code Online (Sandbox Code Playgroud) 我有一个 maven 多模块项目,其中包含一个父模块和三个子模块。该应用程序使用弹簧引导。在其中一个子模块中,我有 SpringBootApplication:
@SpringBootApplication
@EnableConfigurationProperties({AppProperties.class})
public class MainSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MainSpringBootApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用属性在同一个模块中:
@Data
@ConfigurationProperties(prefix = "asdf")
public class AppProperties {
...
}
Run Code Online (Sandbox Code Playgroud)
在该模块的 pom.xml 中有一个 spring-boot-configuration-processor 的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当我在父项目上运行 mvn install 时,未创建此子模块中的 target/classes/META-INF/spring-configuration-metadata.json 文件。当我修改该子模块的 pom 以直接继承时:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Run Code Online (Sandbox Code Playgroud)
直接在子模块上做mvn install,生成target/classes/META-INF/spring-configuration-metadata.json文件。
你有什么提示吗?
我有两个不同的Json文件。
档案A:
{
"label": "A",
"links": [
{
"url": "urla"
}
]
}
Run Code Online (Sandbox Code Playgroud)
档案B:
{
"links": [
{
"url": "urlb"
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,我想用B的内容更新A以得到以下结果Json:
{
"label": "A",
"links": [
{
"url": "urlb"
}
]
}
Run Code Online (Sandbox Code Playgroud)
那就是links应该用B的内容完全替换该数组。但是它将两个数组合并:
{
"label": "A",
"links": [
{
"url": "urla",
"url": "urlb"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是不希望的。合并文件的代码:
JsonNode A = ... // resolved from a service call
JsonNode B = ... // resolved from a service call
ObjectMapper mapper = new ObjectMapper();
result = mapper.readerForUpdating(A).readValue(B); …Run Code Online (Sandbox Code Playgroud)