Search in sources :

Example 56 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication 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)

Example 57 with Authentication

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

the class SshConfigRetrieving method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        // replace it by the CADN or the CA Name
        String template = "<TPP_SSH_CA>";
        // replace it by the TPP User
        String user = "<TPPUSER>";
        // replace it by the TPP Password
        String password = "<TPPPASSWORD>";
        // replace it by the TPP URL
        String baseUri = "<TPP_URL>";
        // 1. Get a VCertClient for TPP setting the scope to "ssh:manage"
        // 1.a The Authentication is optional, but if that is not provided,
        // then the principals of the returned SshConfig object will not be retrieved.
        Authentication auth = Authentication.builder().user(user).password(password).scope("ssh:manage").build();
        Config config = Config.builder().connectorType(ConnectorType.TPP_TOKEN).baseUrl(baseUri).build();
        VCertTknClient client = new VCertTknClient(config);
        client.getAccessToken(auth);
        // 2. Get an instance of com.venafi.vcert.sdk.certificate.SshCaTemplateRequest class.
        SshCaTemplateRequest req = new SshCaTemplateRequest().template(template);
        // 3. Use the VCertClient method retrieveSshConfig() to retrieve the Config of the given
        // SSH CA on TPP.
        // 3.a Remember that Authentication is optional, but if that is not provided,
        // then the principals attribute of the returned SshConfig object will not be retrieved.
        SshConfig sshConfig = client.retrieveSshConfig(req);
        client.revokeAccessToken();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VCertTknClient(com.venafi.vcert.sdk.VCertTknClient) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) Config(com.venafi.vcert.sdk.Config) SshConfig(com.venafi.vcert.sdk.certificate.SshConfig) SshConfig(com.venafi.vcert.sdk.certificate.SshConfig) SshCaTemplateRequest(com.venafi.vcert.sdk.certificate.SshCaTemplateRequest)

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