Search in sources :

Example 1 with VCertClient

use of com.venafi.vcert.sdk.VCertClient in project vcert-java by Venafi.

the class PolicyManagementYamlExample 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.yaml file will be
        String yaml_source_file = "<PARENT_PATH>/policy_specification.yaml";
        // replace it by the path where the policy_specification_result.yaml file will be
        String yaml_target_file = "<PARENT_PATH>/policy_specification_result.yaml";
        // 1. Get an instance of com.venafi.vcert.sdk.policy.domain.PolicySpecification class.
        // At this time it's being to use the Jackson parser to get an instance of PolicySpecification given a Yaml 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(new YAMLFactory());
        mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        PolicySpecification policySpecification = mapper.readValue(new File(yaml_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(yaml_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) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with VCertClient

use of com.venafi.vcert.sdk.VCertClient in project vcert-java by Venafi.

the class CloudClient method main.

public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
    String url = System.getenv("CLOUDURL");
    String zone = System.getenv("CLOUDZONE");
    String appInfo = System.getenv("PRODUCT");
    String apiKey = System.getenv("APIKEY");
    if (zone == null) {
        // or by ID "38992cc0-0177-11ea-a3f0-2b5db8116980";
        zone = "My Project\\My Zone";
    }
    if (appInfo == null)
        appInfo = "My Application 1.0.0.0";
    if (apiKey == null)
        apiKey = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
    Config config = Config.builder().connectorType(ConnectorType.CLOUD).baseUrl(url).appInfo(appInfo).build();
    Authentication auth = Authentication.builder().apiKey(apiKey).build();
    VCertClient client = new VCertClient(config);
    client.authenticate(auth);
    ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
    System.out.println(pemCollection.certificate());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertClient(com.venafi.vcert.sdk.VCertClient) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest)

Example 3 with VCertClient

use of com.venafi.vcert.sdk.VCertClient in project vcert-java by Venafi.

the class TppClient method main.

public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
    String url = System.getenv("TPPURL");
    String zone = System.getenv("TPPZONE");
    String appInfo = System.getenv("PRODUCT");
    String tpp_user = System.getenv("TPPUSER");
    String tpp_passwd = System.getenv("TPPPASSWORD");
    if (tpp_user == null)
        tpp_user = "local:admin";
    if (tpp_passwd == null)
        tpp_passwd = "password";
    if (url == null)
        url = "https://tpp.venafi.example/vedsdk";
    if (zone == null)
        zone = "Certificates\\vcert\\";
    if (appInfo == null)
        appInfo = "CompanyName AppName";
    // Configuration
    Config config = Config.builder().connectorType(ConnectorType.TPP).baseUrl(url).appInfo(appInfo).build();
    Authentication auth = Authentication.builder().user(tpp_user).password(tpp_passwd).build();
    VCertClient client = new VCertClient(config);
    client.authenticate(auth);
    ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
    System.out.println(pemCollection.certificate());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertClient(com.venafi.vcert.sdk.VCertClient) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest)

Example 4 with VCertClient

use of com.venafi.vcert.sdk.VCertClient 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

Config (com.venafi.vcert.sdk.Config)4 VCertClient (com.venafi.vcert.sdk.VCertClient)4 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)2 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)2 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)2 PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)2 File (java.io.File)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1