user3825596
user3825596

Reputation: 161

Access Https Rest Service using Spring RestTemplate (2 way SSL between client and server)

Can anybody provide me with a code sample to access rest service url secured with https using spring rest template.

I have the certificate(.pfx format) password and send cient side certificate to server. server side is used on the client side certificate and established the connection I want to create a springboot application that work as 2 way SSL between client and server. Thanks.

Upvotes: 7

Views: 13280

Answers (1)

SteveO
SteveO

Reputation: 429

I created a sample Spring Boot application that demonstrates how to create a RestTemplate that is configured for SSL client authentication. The sample application acts as the server as well which requires SSL mutual authentication (to demonstrate usage via the test case). In practice, the RestTemplate bean would interact with an external service. Hope this helps.

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

I should note that the most important part of the example is creating the SSLContext. There are plenty of ways to create the SSLContext, I chose a method that uses the SSLContextBuilder from the org.apache.httpcomponents:httpclient library. Other methods such as using the Java API directly, or setting the javax.net.ssl.* JVM properties would also work.

Upvotes: 5

Related Questions