Вот рабочий код Python с использованием библиотеки запросов
Код: Выделить всё
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
Код: Выделить всё
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 token = restClient.post()
.uri(uri)
.header("Accept-Encoding", "base64")
.body(apiKey)
.retrieve().toEntity(String.class);
token.getStatusCode();
return "what";
}
}
Код: Выделить всё
[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
У меня есть сертификаты CA, есть ли способ прикрепить их или передать в RestClient для включить проверку SSL с помощью этого файла?
Подробнее здесь: https://stackoverflow.com/questions/785 ... est-client