I’m trying to replicate the following functionality written in Python using Java Spring Boot.
Here’s the working python code using requests
library
def get_token(conjurHost, conjurAcct, hostName, apiKey):
uri = f"https://{conjurHost}/authn/{conjurAcct}/{hostName}/authenticate"
headers = {"Accept-Encoding": "base64"}
response = requests.post(uri, data=apiKey, headers=headers, verify=False)
token = response.content.decode("utf-8")
return token
and here’s what I’m trying to do in Spring Boot using RestClient
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
@Component
public class ConjurRestClient {
private final RestClient restClient;
private final String conjurHost = "conjur.somecompany.com:443";
private final String conjurAcct = "cyberark";
private final String hostName = "host/apps/APP-PRD-HLO";
public ConjurRestClient(RestClient.Builder builder) {
this.restClient = builder.build();
}
public String getConjurToken(){
String uri = "https://" + conjurHost + "/authn/" + conjurAcct + "/" + hostName + "/" + "authenticate";
String apiKey = "---------redacted---------"; //just a simple api key string
ResponseEntity<String> token = restClient.post()
.uri(uri)
.header("Accept-Encoding", "base64")
.body(apiKey)
.retrieve().toEntity(String.class);
token.getStatusCode();
return "what";
}
}
and I’m getting the following error
[Request processing failed: org.springframework.web.client.ResourceAccessException: I/O error on POST request for https://conjur.somecompany.com:443 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] with root cause
How to fix this error?
I do have ca certificates with me, is there any way to attach them or pass them to the RestClient to enable SSL verification using this file?