Search in sources :

Example 11 with SecretProperties

use of com.microsoft.azure.keyvault.models.SecretProperties in project azure-sdk-for-java by Azure.

the class CertificateOperationsTest method createSelfSignedCertificatePem.

/**
     * Create a self-signed certificate in PEM format (which includes the
     * private key) certificate.
     * 
     * @throws Exception
     */
@Test
public void createSelfSignedCertificatePem() throws Exception {
    // Set content type to indicate the certificate is PKCS12 format.
    SecretProperties secretProperties = new SecretProperties().withContentType(MIME_PEM);
    String subjectName = "CN=SelfSignedJavaPem";
    X509CertificateProperties x509Properties = new X509CertificateProperties().withSubject(subjectName).withValidityInMonths(12);
    // Set issuer to "Self"
    IssuerParameters issuerParameters = new IssuerParameters().withName(ISSUER_SELF);
    CertificatePolicy certificatePolicy = new CertificatePolicy().withSecretProperties(secretProperties).withIssuerParameters(issuerParameters).withX509CertificateProperties(x509Properties);
    String vaultUri = getVaultUri();
    String certificateName = "SelfSignedJavaPem";
    CertificateOperation certificateOperation = keyVaultClient.createCertificate(new CreateCertificateRequest.Builder(vaultUri, certificateName).withPolicy(certificatePolicy).build());
    Assert.assertNotNull(certificateOperation);
    Assert.assertTrue(certificateOperation.status().equalsIgnoreCase(STATUS_IN_PROGRESS));
    CertificateBundle certificateBundle = pollOnCertificateOperation(certificateOperation);
    validateCertificateBundle(certificateBundle, certificatePolicy);
    validatePem(certificateBundle, subjectName);
    CertificateBundle deletedCertificateBundle = keyVaultClient.deleteCertificate(getVaultUri(), certificateName);
    Assert.assertNotNull(deletedCertificateBundle);
    try {
        keyVaultClient.getCertificate(deletedCertificateBundle.certificateIdentifier().baseIdentifier());
    } catch (KeyVaultErrorException e) {
        Assert.assertNotNull(e.body().error());
        Assert.assertEquals("CertificateNotFound", e.body().error().code());
    }
}
Also used : CreateCertificateRequest(com.microsoft.azure.keyvault.requests.CreateCertificateRequest) SecretProperties(com.microsoft.azure.keyvault.models.SecretProperties) CertificateBundle(com.microsoft.azure.keyvault.models.CertificateBundle) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) IssuerParameters(com.microsoft.azure.keyvault.models.IssuerParameters) CertificatePolicy(com.microsoft.azure.keyvault.models.CertificatePolicy) X509CertificateProperties(com.microsoft.azure.keyvault.models.X509CertificateProperties) CertificateOperation(com.microsoft.azure.keyvault.models.CertificateOperation) Test(org.junit.Test)

Aggregations

CertificatePolicy (com.microsoft.azure.keyvault.models.CertificatePolicy)11 SecretProperties (com.microsoft.azure.keyvault.models.SecretProperties)11 Test (org.junit.Test)11 CertificateBundle (com.microsoft.azure.keyvault.models.CertificateBundle)10 KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)9 IssuerParameters (com.microsoft.azure.keyvault.models.IssuerParameters)8 CertificateOperation (com.microsoft.azure.keyvault.models.CertificateOperation)7 X509CertificateProperties (com.microsoft.azure.keyvault.models.X509CertificateProperties)7 CreateCertificateRequest (com.microsoft.azure.keyvault.requests.CreateCertificateRequest)7 SecretIdentifier (com.microsoft.azure.keyvault.SecretIdentifier)3 Attributes (com.microsoft.azure.keyvault.models.Attributes)3 CertificateAttributes (com.microsoft.azure.keyvault.models.CertificateAttributes)3 CertificateItem (com.microsoft.azure.keyvault.models.CertificateItem)3 SecretBundle (com.microsoft.azure.keyvault.models.SecretBundle)3 KeyStore (java.security.KeyStore)3 X509Certificate (java.security.cert.X509Certificate)3 CertificateIdentifier (com.microsoft.azure.keyvault.CertificateIdentifier)2 AdministratorDetails (com.microsoft.azure.keyvault.models.AdministratorDetails)2 IssuerBundle (com.microsoft.azure.keyvault.models.IssuerBundle)2 IssuerCredentials (com.microsoft.azure.keyvault.models.IssuerCredentials)2