我有一个Spring应用程序,它充当两个后端服务器的身份验证代理。用户将访问Spring应用程序,并在通过身份验证后被转发到后端。为了防止在没有事先身份验证的情况下进行不必要的访问,后端服务器需要证书作为身份验证。
我的Spring应用程序使用Netflix-Ribbon作为负载均衡器,使用Netflix-Zuul作为用户请求的代理。如何将它们配置为使用后端服务器上的身份验证所需的客户端证书?
发布于 2020-07-28 20:22:41
好了,我想通了。您可以将自己的CloasableHttpClient配置为@Bean,并创建一个自定义的SSL。您可以通过.loadKeyMaterial()向服务器提供证书。然后,Zuul将使用这些设置。
@Configuration
public class HttpClientConfig {
@Bean
public CloseableHttpClient httpClient() throws Throwable {
String keyPassphrase = "yourCertificatePassword";
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream("Path/to/your/clientCert.pfx"), keyPassphrase.toCharArray());
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, keyPassphrase.toCharArray())
.build();
return HttpClients.custom()
.setSSLContext(sslContext)
.build();
}
}https://stackoverflow.com/questions/62919408
复制相似问题