[英]jhipster microservices client springcloud config with authorization header to jhipster registry
我正在使用 jhipster 7 和 springboot 2.5.4 進行微服務應用程序開發(DEV env)
我已經在 docker 的幫助下設置了在我的本地主機端口 8761 上運行的 jhipster 注冊表服務器。
我正在嘗試訪問 jhipster central springcloud 配置
http://localhost:8761/config/application/prod/main
來自我所有的微服務和網關。
但是,在啟動我的任何微服務和網關時,我收到以下 401 警告:
██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
:: JHipster 🤓 :: Running Spring Boot 2.5.4 ::
:: https://www.jhipster.tech ::
2021-11-04 17:54:01.411 WARN 23468 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 401 Unauthorized: [{
"timestamp" : "2021-11-05T00:54:01.400+00:00",
"status" : 401,
"error" : "Unauthorized",
"message" : "",
"path" : "/config/application/prod/main"
}]
2021-11-04 17:54:01.415 INFO 23468 --- [ main] com.okta.developer.alert.AlertApp : No active profile set, falling back to default profiles: dev,api-docs
2021-11-04 17:54:02.551 DEBUG 23468 --- [ main] i.g.r.utils.RxJava2OnClasspathCondition : RxJava2 related Aspect extensions are not activated, because RxJava2 is not on the classpath.
2021-11-04 17:54:02.552 DEBUG 23468 --- [ main] i.g.r.utils.ReactorOnClasspathCondition : Reactor related Aspect extensions are not activated because Resilience4j Reactor module is not on the classpath.
這是application-dev.yml 中的Spring Cloud 配置之一(不是 bootstrap.yml,因為我不確定是否必須將我的配置放入 bootstrap.yml)
spring:
devtools:
restart:
enabled: true
additional-exclude: static/**
livereload:
enabled: false # we use Webpack dev server + BrowserSync for livereload
jackson:
serialization:
indent-output: true
cloud:
config:
uri: http://admin:${jhipster.registry.password}@localhost:8761/config
# name of the config server's property source (file.yml) that we want to use
name: application
profile: prod
label: main # toggle to switch to a different version of the configuration as stored in git
# it can be set to any label, branch or commit of the configuration source Git repository
我使用 keycloak 作為我的 oauth 服務器,我相信我需要將授權標頭與 GET 請求一起發送到 /config/application/prod/main。
我的中央配置如下所示:
{
"name" : "application",
"profiles" : [ "prod" ],
"label" : "main",
"version" : null,
"state" : null,
"propertySources" : [ {
"name" : "file:central-config/localhost-config/application.yml",
"source" : {
"configserver.name" : "Docker JHipster Registry",
"configserver.status" : "Connected to the JHipster Registry running in Docker",
"jhipster.security.authentication.jwt.base64-secret" : "xxxxxxxxxxxxx",
"eureka.client.service-url.defaultZone" : "http://admin:${jhipster.registry.password}@localhost:8761/eureka/"
}
} ]
}
有人可以幫助我如何擺脫這個 401 錯誤並成功檢索中央配置嗎?
花了一些時間做調查。 該錯誤是由我的網關和微服務中的基本身份驗證配置文件設置不正確引起的。
我注意到下面顯示的application-*.yml中的配置包含一個注冊表密碼
jhipster:
xxxxxxxxx
registry:
password: xxxxxxxxxxxxx
我認為這足以讓我的微服務從 jhipster 注冊表中檢索 spring 雲配置,但實際上並非如此。 我的微服務實際上試圖從bootstrap-*.yml查找注冊表密碼,但由於我沒有用適當的值填充它,因此無法檢索到正確的密碼。 所以我所做的是在bootstrap-*.yml 中對注冊表密碼進行了更新
jhipster:
registry:
password: <correct_password>
現在問題解決了
██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
:: JHipster 🤓 :: Running Spring Boot 2.5.4 ::
:: https://www.jhipster.tech ::
2021-11-08 11:36:28.507 INFO 3872 --- [ main] com.okta.developer.store.StoreApp : No active profile set, falling back to default profiles: dev,api-docs
2021-11-08 11:36:29.639 DEBUG 3872 --- [ main] i.g.r.utils.RxJava2OnClasspathCondition : RxJava2 related Aspect extensions are not activated, because RxJava2 is not on the classpath.
2021-11-08 11:36:29.641 DEBUG 3872 --- [ main] i.g.r.utils.ReactorOnClasspathCondition : Reactor related Aspect extensions are not activated because Resilience4j Reactor module is not on the classpath.
2021-11-08 11:36:29.656 DEBUG 3872 --- [ main] i.g.r.utils.RxJava2OnClasspathCondition : RxJava2 related Aspect extensions are not activated, because RxJava2 is not on the classpath.
@Gaël Marziou,您是對的,我只設置了基本身份驗證而不是 oauth,並且在此修復程序中檢索配置已經足夠了: commit 452728a
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.