我正在尝试为spring cloud eureka服务器启用https.Yaml配置:
server:
port: 8100
ssl:
clientAuth: want
protocol: TLS
key-store: classpath:keystore/keystore.jks
key-store-password: some
key-password: some
eureka:
instance:
prefer-ip-address: true
non-secure-port-enabled: false
secure-port-enabled: true
secure-port: ${server.port}
healthCheckUrl: https://${eureka.hostname}:${secure-port}/health
statusPageUrl: https://${eureka.hostname}:${secure-port}/info
homePageUrl: https://${eureka.hostname}:${secure-port}/
security:
basic:
enabled: true
Run Code Online (Sandbox Code Playgroud)
然后我启动一个客户端注册到服务器.我没有导入cource的自签名证书我得到了exc.security.provider.certpath.SunCertPathBuilderException :无法找到所请求目标的有效证书路径.我不想导入证书,因为有很多实例和证书管理成本很高.因此,我将cert放在classpath中并在启动时加载它.我通过添加代码覆盖客户端默认的ssl上下文和ssl套接字facotory
SSLContext.setDefault(sslContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
Run Code Online (Sandbox Code Playgroud)
它使用假装调用其他eureka客户端时工作正常.但是,在注册到eureka服务器时它没有任何努力.我检查了源代码,发现eureka发现客户端使用jersey,jersey调用http apache客户端.麻烦的是,它使用SchemeRegistryFactory.createDefault(),它将最终调用不考虑系统属性的SSLContexts.createDefault().换句话说,这个http客户端不会标记我的自定义SSLContexts.所以我的问题是,有一种方法可以在eureka发现客户端中添加/重新定位/替换默认的http客户端吗?