jhipster 微服务客户端 springcloud 配置授权 header 到 jhipster 注册表

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 config on

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 云配置之一(不是 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 服务器,我相信我需要将授权 header 连同 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