use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class Examples method main.
public static void main(String... args) throws VCertException, CertificateEncodingException {
final Config config = Config.builder().connectorType(ConnectorType.CLOUD).zone("Default").build();
final VCertClient client = new VCertClient(config);
final Authentication auth = Authentication.builder().apiKey("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").build();
client.authenticate(auth);
final ZoneConfiguration zoneConfiguration = client.readZoneConfiguration("My Project\\My Zone");
// Generate a certificate
CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("cert.test").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA);
certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
// Submit the certificate request
String newCertId = client.requestCertificate(certificateRequest, zoneConfiguration);
// Retrieve PEM collection from Venafi
final CertificateRequest pickupRequest = new CertificateRequest().pickupId(newCertId);
PEMCollection pemCollection = client.retrieveCertificate(pickupRequest);
System.out.println(pemCollection.certificate());
// Renew the certificate
X509Certificate cert = (X509Certificate) pemCollection.certificate();
String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
final CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("cert.test").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah")));
client.generateRequest(zoneConfiguration, certificateRequestToRenew);
final RenewalRequest renewalRequest = new RenewalRequest().thumbprint(thumbprint).request(certificateRequestToRenew);
final String renewedCertificate = client.renewCertificate(renewalRequest);
// Retrieve PEM collection from Venafi
final CertificateRequest renewPickupRequest = new CertificateRequest().pickupId(renewedCertificate);
PEMCollection pemCollectionRenewed = client.retrieveCertificate(pickupRequest);
System.out.println(pemCollectionRenewed.certificate());
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppTokenConnectorTest method setUp.
@BeforeEach
void setUp() throws VCertException {
this.classUnderTest = new TppTokenConnector(tpp);
AuthorizeTokenResponse response = new AuthorizeTokenResponse();
response.accessToken(ACCESS_TOKEN).refreshToken(REFRESH_TOKEN);
when(tpp.authorizeToken(any(TppTokenConnector.AuthorizeTokenRequest.class))).thenReturn(response);
Authentication authentication = Authentication.builder().user("user").password("pass").build();
info = classUnderTest.getAccessToken(authentication);
assertThat(info).isNotNull();
assertThat(info.authorized()).isTrue();
assertThat(info.errorMessage()).isNull();
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppConnectorIT method setup.
@BeforeEach
void setup() throws VCertException {
serverMock.start();
classUnderTest = // todo
new TppConnector(Tpp.connect("http://localhost:" + serverMock.port() + "/vedsdk/"));
// String.format()
Authentication auth = new Authentication("user", "pass", null);
classUnderTest.authenticate(auth);
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppConnectorTest method setUp.
@BeforeEach
void setUp() throws VCertException {
this.classUnderTest = new TppConnector(tpp);
AuthorizeResponse response = new AuthorizeResponse().apiKey(API_KEY).validUntil(OffsetDateTime.now());
when(tpp.authorize(any(TppConnector.AuthorizeRequest.class))).thenReturn(response);
Authentication authentication = new Authentication("user", "pass", null);
classUnderTest.authenticate(authentication);
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppTokenConnectorAT method refreshTokenInvalid.
@Test
@Tag("InvalidAuthentication")
void refreshTokenInvalid() throws VCertException {
Authentication invalidCredentials = Authentication.builder().accessToken("abcde==").refreshToken("1234-1234-12345-123").build();
connectorResource.connector().credentials(invalidCredentials);
TokenInfo info = connectorResource.connector().refreshAccessToken(TestUtils.CLIENT_ID);
assertThat(info).isNotNull();
assertThat(info.authorized()).isFalse();
assertThat(info.errorMessage()).isNotNull();
// After setting invalid credentials to TPP, setting variable <info> to null
// will allow for new token to be authorized
// connectorResource.info(null);
}
Aggregations