Search in sources :

Example 1 with UpdateCertificatePolicyRequest

use of com.microsoft.azure.keyvault.requests.UpdateCertificatePolicyRequest in project azure-sdk-for-java by Azure.

the class AsyncOperationsTest method certificateAsync.

@Test
public void certificateAsync() throws Exception {
    String vault = getVaultUri();
    String certificateName = "myCertificate";
    CreateCertificateRequest createCertificateRequest = new CreateCertificateRequest.Builder(vault, certificateName).withPolicy(new CertificatePolicy().withSecretProperties(new SecretProperties().withContentType("application/x-pkcs12")).withIssuerParameters(new IssuerParameters().withName("Self")).withX509CertificateProperties(new X509CertificateProperties().withSubject("CN=SelfSignedJavaPkcs12").withValidityInMonths(12))).build();
    CertificateOperation certificateOperation = keyVaultClient.createCertificateAsync(createCertificateRequest, null).get();
    Assert.assertNotNull(certificateOperation);
    UpdateCertificateOperationRequest updateCertificateOperationRequest = new UpdateCertificateOperationRequest.Builder(vault, certificateName, false).build();
    certificateOperation = keyVaultClient.updateCertificateOperationAsync(updateCertificateOperationRequest, null).get();
    Assert.assertNotNull(certificateOperation);
    Map<String, String> tags = new HashMap<String, String>();
    tags.put("tag1", "foo");
    UpdateCertificateRequest updateCertificateRequest = new UpdateCertificateRequest.Builder(vault, certificateName).withTags(tags).build();
    CertificateBundle certificateBundle = keyVaultClient.updateCertificateAsync(updateCertificateRequest, null).get();
    Assert.assertNotNull(certificateBundle);
    UpdateCertificatePolicyRequest updateCertificatePolicyRequest = new UpdateCertificatePolicyRequest.Builder(vault, certificateName).build();
    CertificatePolicy certificatePolicy = keyVaultClient.updateCertificatePolicyAsync(updateCertificatePolicyRequest, null).get();
    Assert.assertNotNull(certificatePolicy);
    certificatePolicy = keyVaultClient.getCertificatePolicyAsync(vault, certificateName, null).get();
    Assert.assertNotNull(certificatePolicy);
    certificateOperation = keyVaultClient.getCertificateOperationAsync(vault, certificateName, null).get();
    Assert.assertNotNull(certificateOperation);
    certificateBundle = keyVaultClient.getCertificateAsync(vault, certificateName, null).get();
    Assert.assertNotNull(certificateBundle);
    String cert = keyVaultClient.getPendingCertificateSigningRequestAsync(vault, certificateName, null).get();
    Assert.assertTrue(!cert.isEmpty());
    List<CertificateItem> certificateItem = keyVaultClient.listCertificatesAsync(vault, null).get();
    Assert.assertNotNull(certificateItem);
    List<CertificateItem> certificateVersionItem = keyVaultClient.listCertificateVersionsAsync(vault, certificateName, null).get();
    Assert.assertNotNull(certificateVersionItem);
    keyVaultClient.deleteCertificateOperationAsync(vault, certificateName, null).get();
    keyVaultClient.deleteCertificateAsync(vault, certificateName, null).get();
    try {
        keyVaultClient.deleteCertificateAsync(vault, certificateName, null).get();
    } catch (ExecutionException ex) {
        Throwable t = ex.getCause();
        if (t instanceof KeyVaultErrorException) {
            Assert.assertEquals("CertificateNotFound", ((KeyVaultErrorException) t).body().error().code());
        } else
            throw ex;
    }
}
Also used : HashMap(java.util.HashMap) CertificateBundle(com.microsoft.azure.keyvault.models.CertificateBundle) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) CertificatePolicy(com.microsoft.azure.keyvault.models.CertificatePolicy) IssuerParameters(com.microsoft.azure.keyvault.models.IssuerParameters) UpdateCertificateOperationRequest(com.microsoft.azure.keyvault.requests.UpdateCertificateOperationRequest) X509CertificateProperties(com.microsoft.azure.keyvault.models.X509CertificateProperties) CertificateOperation(com.microsoft.azure.keyvault.models.CertificateOperation) UpdateCertificatePolicyRequest(com.microsoft.azure.keyvault.requests.UpdateCertificatePolicyRequest) CreateCertificateRequest(com.microsoft.azure.keyvault.requests.CreateCertificateRequest) SecretProperties(com.microsoft.azure.keyvault.models.SecretProperties) CertificateItem(com.microsoft.azure.keyvault.models.CertificateItem) UpdateCertificateRequest(com.microsoft.azure.keyvault.requests.UpdateCertificateRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

CertificateBundle (com.microsoft.azure.keyvault.models.CertificateBundle)1 CertificateItem (com.microsoft.azure.keyvault.models.CertificateItem)1 CertificateOperation (com.microsoft.azure.keyvault.models.CertificateOperation)1 CertificatePolicy (com.microsoft.azure.keyvault.models.CertificatePolicy)1 IssuerParameters (com.microsoft.azure.keyvault.models.IssuerParameters)1 KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)1 SecretProperties (com.microsoft.azure.keyvault.models.SecretProperties)1 X509CertificateProperties (com.microsoft.azure.keyvault.models.X509CertificateProperties)1 CreateCertificateRequest (com.microsoft.azure.keyvault.requests.CreateCertificateRequest)1 UpdateCertificateOperationRequest (com.microsoft.azure.keyvault.requests.UpdateCertificateOperationRequest)1 UpdateCertificatePolicyRequest (com.microsoft.azure.keyvault.requests.UpdateCertificatePolicyRequest)1 UpdateCertificateRequest (com.microsoft.azure.keyvault.requests.UpdateCertificateRequest)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1