【问题标题】:How can I authenticate a Ribbon load balancer and Zuul proxy using a certificate?如何使用证书对 Ribbon 负载均衡器和 Zuul 代理进行身份验证?
【发布时间】:2020-11-05 05:16:29
【问题描述】:

我有一个 Spring 应用程序,它充当两个后端服务器的身份验证代理。一旦成功通过身份验证,用户将访问 Spring 应用程序并被转发到后端。为了防止未经事先身份验证的意外访问,后端服务器需要证书作为身份验证。

我的 Spring 应用程序使用 Netflix-Ribbon 作为负载平衡器,使用 Netflix-Zuul 作为用户请求的代理。如何配置它们以使用在后端服务器上进行身份验证所需的客户端证书?

【问题讨论】:

    标签: spring authentication certificate netflix-zuul netflix-ribbon


    【解决方案1】:

    好的,我想通了。您可以将自己的 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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多