E
E
evrikom2020-04-23 06:44:03
Java
evrikom, 2020-04-23 06:44:03

How to install a certificate in the Jersey client for authentication on the server?

Good afternoon.
Generated x.509 server and client certificates, keystore, truststore based on the article
" https://dzone.com/articles/securing-rest-apis-with... "
On the server (Spring-boot 2.1) enabled https. Imported the client keystore (.p12) into the browser, the server responds, everything is ok.
On the java client I use jersey client 2.26

, the setup is as follows:

HostnameVerifier allHostsValid = (hostname, session) -> true;
 SslConfigurator sslConfig = SslConfigurator.newInstance()
                    .keyStoreFile("/path/to/client/keystore/client.p12")
                    .keyStoreType("PKCS12")
                    .keyPassword("password");

  SSLContext sslContext = sslConfig.createSSLContext();
  Client client = ClientBuilder.newBuilder()
                                            .sslContext(sslContext)
                                            .hostnameVerifier(allHostsValid)
                                            .register(feature)
                                            .build();

When I make a request to the server, I get:
SunCertPathBuilderException: unable to find valid certification path to requested target

With commented out line
.sslContext(getSslContext(
)) the same error.
because the server-browser connection is working, I'm setting up the jersey client incorrectly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question