SpringBootAdmin 监控Https服务记录

前言:

在搭建SpringBootAdmin监控服务时发现,如果对https服务进行监控会存在问题,在网上看到了一些导入证书的,操作起来较为繁琐,查阅SpringBootAdmin官方文档后发现,其提供了一个扩展ClientHttpConnector,详细说明可查阅官方文档。

解决方案:

引用下官方文档的一段简介:

SBA Server can also use client certificates to authenticate when accessing the actuator endpoints. If a custom configured ClientHttpConnector bean is present, Spring Boot will automatically configure a WebClient.Builder using it, which will be used by Spring Boot Admin.

配置Bean即可,可在SpringBoot启动类中写入,代码如下:

@Bean
    public ClientHttpConnector customHttpClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, SSLException {
        SslContextBuilder sslContext = SslContextBuilder.forClient();
        X509TrustManager x509mgr = new X509TrustManager() {

            //检查客户端证书,若不信任该证书则抛出异常
            public void checkClientTrusted(X509Certificate[] xcs, String string) {
            }
            //检查服务端证书,如不信任该证书则抛出异常
            public void checkServerTrusted(X509Certificate[] xcs, String string) {
            }
            //返回受信任的X509证书
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        sslContext.trustManager(x509mgr);
        //Your sslContext customizations go here
        HttpClient httpClient = HttpClient.create().secure(
                ssl -> ssl.sslContext(sslContext)
        );
        return new ReactorClientHttpConnector(httpClient);
    }

这样即可跳过SpringBootAdmin对https的验证

参考:

SpringBootAdmin官方文档:

https://codecentric.github.io/spring-boot-admin/current/#_using_mutual_tls

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值