Мне не удается выполнить успешный запрос SOAP через SSL с сертификатом клиента. Поскольку у меня есть несколько исходящих соединений с разными клиентскими сертификатами, мне приходится программно обрабатывать хранилище ключей. Вы найдете мой код Java ниже.
Если я установил -Djavax.net.debug=all
, я нашел эту строку в журналах:
Warning: no suitable certificate found - continuing without client authentication
Так что это довольно очевидно, но я не знаю, почему это происходит. Любые идеи, что не так или как это отладить?
SSLContext sc = SSLContext.getInstance("SSL");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance("JKS");
InputStream is = getClass().getResourceAsStream("/path_to_client_certificate.p12");
Assert.assertNotNull(is);
ks.load(is, "my_password".toCharArray());
kmf.init(ks, "my_password".toCharArray());
sc.init(kmf.getKeyManagers(), null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
URL url = getClass().getClassLoader().getResource("/path_to_local_wsdl_file.wsdl");
BillingService billingService = new BillingService(url);
BoBillingService boBillingService = billingService.getWsHttp();
BindingProvider bindingProvider = (BindingProvider) boBillingService;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"https://www.hostname.com/service_path");
ExecutePingOut executePingOut = boBillingService.executePing("My Text", true);
LOGGER.trace(executePingOut.getMessage().getValue());
Выполнение этого кода дает следующий результат:
---[HTTP request - https://www.hostname.com/service_path]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "https://www.hostname.com/service_path/ExecutePing"
User-Agent: JAX-WS RI 2.2.8 svn-revision#13980
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ExecutePing xmlns="https://www.hostname.com/service_path" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns3="http://schemas.datacontract.org/2004/07/EBS.BO.Billing">
<text>My Text</text>
<exceptionTest>true</exceptionTest>
</ExecutePing>
</S:Body>
</S:Envelope>--------------------
---[HTTP response - https://www.hostname.com/service_path - 500]---
null: HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 311
Content-Type: text/xml; charset=utf-8
Date: Fri, 18 Mar 2016 05:31:31 GMT
Server: Apache (proxied)
Set-Cookie: ittrksessid=6d564320.52e4c0f3a5ec0; path=/; domain=.hostname.ch
Strict-Transport-Security: max-age=15768000
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:FailedAuthentication</faultcode>
<faultstring xml:lang="de-CH">Access is denied.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>