簡體   English   中英

Outboud連接上的客戶端證書

[英]Client certificate on outboud connection

在我的應用程序上,我需要使用客戶端身份驗證訪問一堆REST Web服務。 我正在使用RestEasy的JAX-RS Client實現(實際上是在后台使用Apache HttpComponents)。

首先,我嘗試加載KeyStore

private static KeyStore keyStore;

static {
    try {
        String keyStoreProperty = System.getProperty("javax.net.ssl.keyStore");
        String keyStorePasswordProperty = System.getProperty("javax.net.ssl.keyStorePassword");

        if (keyStoreProperty != null && keyStorePasswordProperty != null) {
            keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            try (InputStream keyStoreData = new FileInputStream(keyStoreProperty)) {
                keyStore.load(keyStoreData, keyStorePasswordProperty.toCharArray());
            }
        }
    } catch (IOException | NoSuchAlgorithmException | CertificateException | KeyStoreException e) {
        //logging
    }
}

接下來,我使用先前加載的KeyStore來構建javax.ws.rs.client.Client

Client client;
if (keyStore != null) {
    client = ClientBuilder.newBuilder()
        .keyStore(keyStore, System.getProperty("javax.net.ssl.keyStorePassword")).build();
} else {
    //logging
}

但是,這段代碼似乎並不是正確的處理方式。

我想知道是否有可能在JBoss / WildFly上配置keyStore並將其應用於出站連接,最好基於URL模式。

WildFly沒有。

關於在配置2向SSL時的代碼,還需要配置trustStore。 為了使客戶端信任服務器,您正在連接。 或者,也可以使用ssl上下文代替keyStore trustStore對[1]。

[1] https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/ClientBuilder.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM