Search in sources :

Example 26 with Authentication

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());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) X509Certificate(java.security.cert.X509Certificate)

Example 27 with Authentication

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();
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with Authentication

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);
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with Authentication

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);
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with 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);
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

Authentication (com.venafi.vcert.sdk.endpoint.Authentication)57 Test (org.junit.jupiter.api.Test)36 DisplayName (org.junit.jupiter.api.DisplayName)31 PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)24 VCertException (com.venafi.vcert.sdk.VCertException)22 IOException (java.io.IOException)22 Config (com.venafi.vcert.sdk.Config)9 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 VCertTknClient (com.venafi.vcert.sdk.VCertTknClient)5 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)5 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)5 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)5 VCertClient (com.venafi.vcert.sdk.VCertClient)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Tag (org.junit.jupiter.api.Tag)3 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 CertificateStatus (com.venafi.vcert.sdk.certificate.CertificateStatus)2