0

I have the location of certificate. Can someone guide me on how to add certificate to the HTTP header in RestTemplate. Below is how I am building the RestTemplate. The certificate needs to be in a header by name ssl-client-cert. Should this be done in the code or configures on the web server?

public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {

SSLContext sslContext;

KeyStore keystore = KeyStore.getInstance("JKS");
FileInputStream ks = new FileInputStream("<path>");
FileInputStream ts = new FileInputStream("<path>");
keystore.load(ks,"changeit".toCharArray());
KeyStore truststore = KeyStore.getInstance("JKS");
truststore.load(ts,"changeit".toCharArray());

sslContext = SSLContextBuilder.create()
.loadKeyMaterial(keystore, global.getstorePass().toCharArray())
.loadTrustMaterial(truststore, new TrustSelfSignedStrategy())
.build();

HttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
            .build();

return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();

}
  • Possible duplicate of [What is the right way to send a client certificate with every request made by the resttemplate in spring?](https://stackoverflow.com/questions/45713593/what-is-the-right-way-to-send-a-client-certificate-with-every-request-made-by-th) – pvpkiran Jan 08 '18 at 15:44
  • 1
    I developed the code based on the above stackoverflow thread but I get a 403 forbidden error. The certifcate is in the request but the web service is looking for it in a http header with name "ssl-client-cert". how to do this? – rookieDeveloper Jan 08 '18 at 15:50

0 Answers0