Spring Cloud Config客户端安全认证机制JWT实战

一 代码位置

https://github.com/cakin24/spring-cloud-code/tree/master/ch12-7

二 测试认证通过

1 客户端配置

spring:
    cloud:
        config:
            label: master
            uri: http://localhost:9090
            name: config-info
            profile: dev
            username: root
            password: 123
            enabled: false
            endpoint: http://localhost:9090/auth

2 服务端配置

spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/cakin24/spring-cloud-config.git
          search-paths: SC-BOOK-CONFIG
          force-pull: true
  application:
    name: ch12-7-config-server-auth-jwt


  security:
    user:
      name: root
      password: 123


server:
    port: 9090

3 启动服务端 config-server-auth-jwt

4 启动客户端 config-client-auth-jwt

5 浏览器输入  http://localhost:9014/configConsumer/getConfigInfo

三 测试认证不通过

1 客户端配置

spring:
    cloud:
        config:
            label: master
            uri: http://localhost:9090
            name: config-info
            profile: dev
            username: root
            password: 124
            enabled: false
            endpoint: http://localhost:9090/auth

2 启动客户端 config-client-auth-jwt

2019-11-21 19:21:51.387  INFO 21420 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7770f470: startup date [Thu Nov 21 19:21:51 CST 2019]; root of context hierarchy
2019-11-21 19:21:51.575  INFO 21420 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'configClientProperties' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configServiceBootstrapConfiguration; factoryMethodName=configClientProperties; initMethodName=null; destroyMethodName=(inferred); defined in org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configClientBootstrapConfiguration; factoryMethodName=configClientProperties; initMethodName=null; destroyMethodName=(inferred); defined in cn.springcloud.book.config.jwt.config.ConfigClientBootstrapConfiguration]
2019-11-21 19:21:51.760  INFO 21420 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$dff1a320] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
org.springframework.web.client.HttpClientErrorException: 401 null

无法启动,因为密码不匹配。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值