有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java强制ReactorClientHttpConnector将p12证书用于httpClient

我使用SpringCloudGateway,其中ReactorClientHttpConnector用于发出http请求。http请求的目标需要客户端证书。我尝试使用后处理器设置HttpClient bean,但没有帮助

override fun postProcessBeforeInitialization(bean: Any, beanName: String): Any? {
        if (bean is HttpClient) {
            val password = System.getProperty("javax.net.ssl.keyStorePassword")
            val appKeyStore: KeyStore = KeyStore.getInstance("PKCS12")
            appKeyStore.load(FileInputStream("/etc/secrets/cert.p12"), password.toCharArray())
            val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance("SunX509")
            keyManagerFactory.init(appKeyStore, password.toCharArray())
            val sslContextBuilder = SslContextBuilder.forClient()
                .keyManager(keyManagerFactory)
                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                .build();
            return bean.secure { it.sslContext(sslContextBuilder) }
        }
        return super.postProcessBeforeInitialization(bean, beanName)
    }

有没有办法配置HttpClient,以便所有请求都使用我的p12证书


共 (0) 个答案