1.get Zertifikat Webservice Sie wollen.
2.create Schlüsselspeicher mit diesem cerificate.
3.ssl Config-Client mit Schlüsselspeicher:
@Configuration
public class WebServiceClient {
@Inject
private PaymentProperties paymentProperties;
@Autowired
private ResourceLoader resourceLoader;
@Bean(name = "PaymentWebService")
public PaymentWebService PaymentWebServiceCLient() throws MalformedURLException {
JaxWsProxyFactoryBean factory;
factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(PaymentWebService.class);
// factory.setAddress("http://localhost:8080/ws/merchantAuth_1.0");
factory.setAddress(paymentProperties.getWsPublicUrl());
PaymentWebService service = (PaymentWebService) factory.create();
try {
final Client client = ClientProxy.getClient(service);
setupSsl((HTTPConduit) ClientProxy.getClient(service).getConduit());
} catch (Exception e) {
}
return service;
}
private void setupSsl(HTTPConduit httpConduit) throws Exception {
final TLSClientParameters tlsCP = new TLSClientParameters();
final String keyStoreLoc = paymentProperties.getSsl().getKeyStore();
final String keyPassword = paymentProperties.getSsl().getKeyStorePassword();
final String keystoreType = paymentProperties.getSsl().getKeyStoreType();
final KeyStore keyStore = KeyStore.getInstance(keystoreType);
Resource resource1 = resourceLoader.getResource(keyStoreLoc);
keyStore.load(resource1.getInputStream(), keyPassword.toCharArray());
final KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
tlsCP.setKeyManagers(myKeyManagers);
final String trustStoreLoc = paymentProperties.getSsl().getTrustStore();
final String trustStorePassword = paymentProperties.getSsl().getTrustStorePassword();
final String trustStoreType = paymentProperties.getSsl().getTrustStoreType();
final KeyStore trustStore = KeyStore.getInstance(trustStoreType);
Resource resource2 = resourceLoader.getResource(trustStoreLoc);
trustStore.load(resource2.getInputStream(), trustStorePassword.toCharArray());
final TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
tlsCP.setTrustManagers(myTrustStoreKeyManagers);
httpConduit.setTlsClientParameters(tlsCP);
}
private static TrustManager[] getTrustManagers(KeyStore trustStore)
throws NoSuchAlgorithmException, KeyStoreException {
String alg = KeyManagerFactory.getDefaultAlgorithm();
TrustManagerFactory fac = TrustManagerFactory.getInstance(alg);
fac.init(trustStore);
return fac.getTrustManagers();
}
private static KeyManager[] getKeyManagers(KeyStore keyStore, String keyPassword)
throws GeneralSecurityException, IOException {
String alg = KeyManagerFactory.getDefaultAlgorithm();
char[] keyPass = keyPassword != null ? keyPassword.toCharArray() : null;
KeyManagerFactory fac = KeyManagerFactory.getInstance(alg);
fac.init(keyStore, keyPass);
return fac.getKeyManagers();
}
}
Bitte erläutern und wenn es möglich ist, die Konfigurationsschritte zu beschreiben. –