Search in sources :

Example 1 with Application

use of com.venafi.vcert.sdk.connectors.cloud.domain.Application in project vcert-java by Venafi.

the class CloudConnectorUtils method createAppForCit.

private static void createAppForCit(CertificateIssuingTemplate cit, String appName, String apiKey, Cloud cloud) throws VCertException {
    UserDetails userDetails = cloud.authorize(apiKey);
    String userId = userDetails.user().id();
    Application application = new Application();
    Application.OwnerIdsAndType ownerIdsAndType = new Application.OwnerIdsAndType();
    ownerIdsAndType.ownerId(userId);
    ownerIdsAndType.ownerType("USER");
    List<Application.OwnerIdsAndType> ownerIdsAndTypes = new ArrayList<>();
    ownerIdsAndTypes.add(ownerIdsAndType);
    Map<String, String> citAliasIdMap = new HashMap<>();
    citAliasIdMap.put(cit.name(), cit.id());
    application.name(appName);
    application.ownerIdsAndTypes(ownerIdsAndTypes);
    application.certificateIssuingTemplateAliasIdMap(citAliasIdMap);
    cloud.createApplication(application, apiKey);
}
Also used : UserDetails(com.venafi.vcert.sdk.connectors.cloud.domain.UserDetails) Application(com.venafi.vcert.sdk.connectors.cloud.domain.Application)

Example 2 with Application

use of com.venafi.vcert.sdk.connectors.cloud.domain.Application in project vcert-java by Venafi.

the class CloudConnectorUtils method setCitToApp.

public static void setCitToApp(String policyName, CertificateIssuingTemplate cit, /*, CloudPolicy.CAInfo caInfo*/
String apiKey, Cloud cloud) throws VCertException {
    // getting the cloud zone
    CloudZone zone = new CloudZone(policyName);
    Application application = null;
    try {
        application = cloud.applicationByName(zone.appName(), apiKey);
    } catch (FeignException exception) {
        if (exception.status() != 404) {
            throw exception;
        }
    }
    // then it will needed to create it
    if (application == null)
        // create the application and related it with the cit
        createAppForCit(cit, zone.appName(), apiKey, cloud);
    else
        // update the application with the relation to the cit if that is not existing
        addCitToApp(cit, application, apiKey, cloud);
}
Also used : FeignException(feign.FeignException) Application(com.venafi.vcert.sdk.connectors.cloud.domain.Application) CloudZone(com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)

Example 3 with Application

use of com.venafi.vcert.sdk.connectors.cloud.domain.Application in project vcert-java by Venafi.

the class CloudConnectorTest method requestCertificate.

@Test
void requestCertificate() throws VCertException {
    Security.addProvider(new BouncyCastleProvider());
    String apiKey = "12345678-1234-1234-1234-123456789012";
    CertificateIssuingTemplate cit = new CertificateIssuingTemplate();
    cit.id("15c7e3f0-ff0a-11e9-a3f0-2b5db8116980");
    cit.keyTypes(Arrays.asList(new AllowedKeyType("RSA", Arrays.asList(2048))));
    cit.keyReuse(true);
    cit.subjectCNRegexes(Arrays.asList("^random name$", "^.*.example.com$", "^.*.example.org$", "^.*.example.net$", "^.*.invalid$", "^.*.local$", "^.*.localhost$", "^.*.test$"));
    cit.subjectORegexes(Arrays.asList("^.*$"));
    cit.subjectOURegexes(Arrays.asList("^.*$"));
    cit.subjectSTRegexes(Arrays.asList());
    cit.subjectLRegexes(Arrays.asList());
    cit.subjectCValues(Arrays.asList());
    cit.sanDnsNameRegexes(Arrays.asList());
    Application application = new Application();
    application.id("d3d7e270-545b-11eb-a494-893c4e1e4fad");
    when(cloud.applicationByName(eq("test_app"), eq(apiKey))).thenReturn(application);
    when(cloud.certificateIssuingTemplateByAppNameAndCitAlias(eq("test_app"), eq("test_zone"), eq(apiKey))).thenReturn(cit);
    // todo:
    when(cloud.certificateRequest(eq(apiKey), any(CloudConnector.CertificateRequestsPayload.class))).thenReturn(new CloudConnector.CertificateRequestsResponse().certificateRequests(singletonList(new CloudConnector.CertificateRequestsResponseData().id("jackpot"))));
    CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("random name").organization(singletonList("Venafi, Inc.")).organizationalUnit(singletonList("Automated Tests")));
    final Authentication auth = new Authentication(null, null, apiKey);
    classUnderTest.authenticate(auth);
    ZoneConfiguration zoneConfig = classUnderTest.readZoneConfiguration("test_app\\test_zone");
    classUnderTest.generateRequest(zoneConfig, request);
    String actual = classUnderTest.requestCertificate(request, zoneConfig);
    assertThat(actual).isEqualTo("jackpot");
}
Also used : CertificateIssuingTemplate(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) AllowedKeyType(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate.AllowedKeyType) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Application(com.venafi.vcert.sdk.connectors.cloud.domain.Application) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.jupiter.api.Test)

Aggregations

Application (com.venafi.vcert.sdk.connectors.cloud.domain.Application)3 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)1 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)1 CertificateIssuingTemplate (com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate)1 AllowedKeyType (com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate.AllowedKeyType)1 CloudZone (com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)1 UserDetails (com.venafi.vcert.sdk.connectors.cloud.domain.UserDetails)1 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)1 FeignException (feign.FeignException)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1