2

方法是否通过 oauth2 令牌保护配置服务器?

我计划通过 oauth2 令牌实现 spring 云配置服务器,因此客户端服务器可以通过以下方式获取属性:

 cloud:
    config:
      uri: http://user:password@localhost:8888

可行吗?

但是……我遇到了一些问题。我开始演示 https://github.com/keryhu/spring-oauth2-config-server.git

它包含四项服务:

1:eureka:先启动,可以实现服务注册和发现,没有oauth2环境。

2:auth-server:JWT OAuth2服务器配置,其次启动。

    @SessionAttributes("authorizationRequest")
    @EnableResourceServer
    @EnableDiscoveryClient

和内存用户:

  security:
    user:
      password: password

3: config-server : 第三次启动

@EnableDiscoveryClient
@EnableConfigServer
@EnableResourceServer

在 application.yml 中:

spring:  
  cloud:
     config:
       server:
         git:
           uri: https://github.com/keryhu/cloud-config


security:
  oauth2:
    resource:
      jwt:
        keyValue: |
          -----BEGIN PUBLIC KEY-----
          ....
          -----END PUBLIC KEY-----

4:pc-gateway:是一个客户端-服务器,也是一个ui服务器。最后开始

当我测试安全 uri: http://localhost:8080/hello时,页面被重定向到

http://localhost:9999/uua/login

输入“用户:密码”后,它重定向回来

http://localhost:8080/hello

所以我认为 oauth-server 和 oauth-client 很好。

但是..我还在 bootstrap.yml 中设置了以下配置

cloud:
    config:
      uri: http://user:password@localhost:8888

启动 pc-gateway 服务时,从服务器获取配置有 401 Unauthorized 错误:

INFO 954 --- [main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
WARN 954 --- [main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 401 Unauthorized

需要帮忙 !谢谢 !

4

0 回答 0