Accessing Https Rest Service with Spring RestTemplate (two-way SSL between client and server)

Can anyone provide me with sample code for accessing an https protected service url using the spring rest pattern.

I have a password for the certificate (.pfx) and send the cient side certificate to the server. the server is used on the client side certificate and established a connection I want to create a springboot application that works like two ways SSL between client and server. Thank.

+3


source to share


1 answer


I created a sample Spring Boot application demonstrating how to create RestTemplate

one configured for SSL client authentication. The sample application also acts as a server that requires SSL authentication (to demonstrate use through a test case). In practice, the RestTemplate

bean will interact with an external service. Hope this helps.

https://github.com/steve-oakey/spring-boot-sample-clientauth



It should be noted that the most important part of the example is creation SSLContext

. There are many ways to create SSLContext

, I chose the method that uses SSLContextBuilder

from the library org.apache.httpcomponents:httpclient

. Other methods, such as using the Java API directly or setting javax.net.ssl.*

JVM properties , will also work.

+2


source







All Articles