Search in sources :

Example 56 with PolicySpecification

use of com.venafi.vcert.sdk.policy.domain.PolicySpecification in project vcert-java by Venafi.

the class TppTokenConnectorTest method testExceptionValidatingDefaultOrg.

@Test
@DisplayName("TPP - Testing Exception in Validation of Defaults Org not matching with the Policy Orgs values")
public void testExceptionValidatingDefaultOrg() throws VCertException {
    PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
    // setting the Default Org to a value which doesn't match with the values in the
    // Policy Orgs values to validate that the related VCertException is thrown
    policySpecification.defaults().subject().org("Ven");
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
    Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_SUBJECT_ORG, PolicySpecificationConst.ATT_POLICY_SUBJECT_ORGS), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) FeignException(feign.FeignException) VCertException(com.venafi.vcert.sdk.VCertException) FailedToRevokeTokenException(com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 57 with PolicySpecification

use of com.venafi.vcert.sdk.policy.domain.PolicySpecification in project vcert-java by Venafi.

the class PolicyManagementJsonExample method main.

public static void main(String[] args) {
    try {
        // replace it by the policy full name
        String policyName = "<APP_NAME>\\<CIT_ALIAS>";
        // replace it by the api-key
        String tppl_api_key = "<APIKEY>";
        // replace it by the path where the policy_specification.json file will be
        String json_source_file = "<PARENT_PATH>/policy_specification.json";
        // replace it by the path where the policy_specification_result.json file will be
        String json_target_file = "<PARENT_PATH>/policy_specification_result.json";
        // 1. Get an instance of com.venafi.vcert.sdk.policy.domain.PolicySpecification class.
        // At this time it is going to use the Jackson parser to get an instance of PolicySpecification given a Json file.
        // You can learn more about Jackson parser in https://github.com/FasterXML/jackson
        // and http://tutorials.jenkov.com/java-json/jackson-objectmapper.html
        ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        PolicySpecification policySpecification = mapper.readValue(new File(json_source_file), PolicySpecification.class);
        // 2. Get a VCertClient. For this time, it's going to use a VCertClient for Cloud.
        Authentication auth = Authentication.builder().apiKey(tppl_api_key).build();
        Config config = Config.builder().connectorType(ConnectorType.CLOUD).build();
        VCertClient client = new VCertClient(config);
        client.authenticate(auth);
        // 3. Use the VCertClient method setPolicy() to set a Policy.
        // If the the policy doesn't exist then it will be created.
        // If the the policy exists then it will be updated.
        client.setPolicy(policyName, policySpecification);
        // 4. You can get the Policy which you created/updated using the getPolicy method and then use it
        // to write it in json format using the Jackson parser.
        PolicySpecification policyTemp = client.getPolicy(policyName);
        mapper.writeValue(new File(json_target_file), policyTemp);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) Config(com.venafi.vcert.sdk.Config) VCertClient(com.venafi.vcert.sdk.VCertClient) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)57 DisplayName (org.junit.jupiter.api.DisplayName)49 Test (org.junit.jupiter.api.Test)49 VCertException (com.venafi.vcert.sdk.VCertException)48 CertificateDNOrThumbprintWasNotProvidedException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException)24 CertificateNotFoundByThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException)24 MoreThanOneCertificateWithSameThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)24 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)24 FeignException (feign.FeignException)24 IOException (java.io.IOException)24 FailedToRevokeTokenException (com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Config (com.venafi.vcert.sdk.Config)2 VCertClient (com.venafi.vcert.sdk.VCertClient)2 CertificateIssuingTemplate (com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate)2 TPPPolicy (com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)1 ChainOption (com.venafi.vcert.sdk.certificate.ChainOption)1 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)1