From 571391eedff91673f64ab3d9a16c0b9ebe643a2c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 8 Aug 2016 18:16:18 -0700 Subject: [PATCH] Allow specifying upn and spn --- .../graphrbac/ServicePrincipals.java | 17 ++- .../azure/management/graphrbac/Users.java | 11 ++ .../implementation/ServicePrincipalsImpl.java | 32 +++- .../graphrbac/implementation/UsersImpl.java | 24 +++ .../management/keyvault/AccessPolicy.java | 5 + .../implementation/AccessPolicyImpl.java | 25 +++- .../keyvault/implementation/VaultImpl.java | 137 ++++++++++++------ .../keyvault/implementation/VaultsImpl.java | 6 +- .../keyvault/KeyVaultManagementTestBase.java | 33 +++-- .../azure/management/keyvault/VaultTests.java | 12 +- .../microsoft/azure/ParallelServiceCall.java | 50 +++++++ .../com/microsoft/azure/TaskGroupBase.java | 48 +----- 12 files changed, 276 insertions(+), 124 deletions(-) create mode 100644 runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java index 15714e3836e8c..96bc608cf9d74 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -9,6 +9,8 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; import java.io.IOException; @@ -25,7 +27,7 @@ public interface ServicePrincipals extends * @param objectId the unique object id * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByObjectId(String objectId) throws GraphErrorException, IOException; @@ -35,7 +37,7 @@ public interface ServicePrincipals extends * @param appId the application id (or the client id) * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOException; @@ -45,7 +47,16 @@ public interface ServicePrincipals extends * @param spn the service principal name * @return an immutable representation of the resource * @throws GraphErrorException exceptions thrown from the graph API - * @throws IOException exceptions thrown from serialization/deserialization + * @throws IOException exceptions thrown from serialization/deserialization */ ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException; + + /** + * Gets the information about a service principal. + * + * @param spn the service principal name + * @param callback the call back to handle response + * @return the Future based service call + */ + ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java index e2432276fef95..42b09e31b2956 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -9,6 +9,8 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; import java.io.IOException; @@ -38,4 +40,13 @@ public interface Users extends * @throws IOException exceptions thrown from serialization/deserialization */ User getByUserPrincipalName(String upn) throws GraphErrorException, IOException; + + /** + * Gets the information about a user. + * + * @param upn the user principal name + * @param callback the callback to handle the response + * @return an Future based service call + */ + ServiceCall getByUserPrincipalNameAsync(String upn, ServiceCallback callback); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java index ec0c86cfdad90..bc7f797736ebe 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -11,8 +11,12 @@ import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.graphrbac.ServicePrincipals; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import java.io.IOException; +import java.util.List; /** * The implementation of StorageAccounts and its parent interfaces. @@ -70,6 +74,32 @@ public ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOE @Override public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException { - return null; + List spList = innerCollection.list(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)).getBody(); + if (spList == null || spList.isEmpty()) { + return null; + } else { + return new ServicePrincipalImpl(spList.get(0), innerCollection); + } + } + + @Override + public ServiceCall getByServicePrincipalNameAsync(String spn, final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + serviceCall.newCall(innerCollection.getAsync(spn, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + ServicePrincipal user = new ServicePrincipalImpl(result.getBody(), innerCollection); + ServiceResponse clientResponse = new ServiceResponse<>(user, result.getResponse()); + callback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + return serviceCall; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 3bbdb8db31da3..66515f776f3d6 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -12,6 +12,9 @@ import com.microsoft.azure.management.graphrbac.Users; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; import com.microsoft.rest.RestException; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import java.io.IOException; @@ -68,4 +71,25 @@ public UserImpl getByObjectId(String objectId) throws GraphErrorException, IOExc public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, IOException { return new UserImpl(innerCollection.get(upn).getBody(), innerCollection); } + + @Override + public ServiceCall getByUserPrincipalNameAsync(String upn, final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + serviceCall.newCall(innerCollection.getAsync(upn, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + User user = new UserImpl(result.getBody(), innerCollection); + ServiceResponse clientResponse = new ServiceResponse(user, result.getResponse()); + callback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + return serviceCall; + } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index e62eb48261a6a..bf26fc88f18d7 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -69,8 +69,10 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); + WithAttach forUser(String userPrincipalName); WithAttach forGroup(Group group); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + WithAttach forServicePrincipal(String servicePrincipalName); } /** @@ -120,7 +122,10 @@ interface Blank extends WithIdentity { interface WithIdentity { WithAttach forObjectId(UUID objectId); WithAttach forUser(User user); + WithAttach forUser(String userPrincipalName); + WithAttach forGroup(Group group); WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); + WithAttach forServicePrincipal(String servicePrincipalName); } /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index b364a3f08e990..32928758577ea 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -34,6 +34,8 @@ class AccessPolicyImpl AccessPolicy.Definition, AccessPolicy.UpdateDefinition, AccessPolicy.Update { + String userPrincipalName; + String servicePrincipalName; AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { super(innerObject, parent); @@ -119,34 +121,48 @@ public VaultImpl attach() { @Override public AccessPolicyImpl forObjectId(UUID objectId) { inner().withObjectId(objectId); + inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forUser(User user) { inner().withObjectId(UUID.fromString(user.objectId())); + inner().withTenantId(parent().tenantId()); + return this; + } + + @Override + public AccessPolicyImpl forUser(String userPrincipalName) { + this.userPrincipalName = userPrincipalName; return this; } @Override public AccessPolicyImpl forGroup(Group group) { inner().withObjectId(UUID.fromString(group.objectId())); + inner().withTenantId(parent().tenantId()); return this; } @Override public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); + inner().withTenantId(parent().tenantId()); return this; } @Override - public AccessPolicyImpl allowKeyAllPermissions() { - initializeKeyPermissions(); - // TODO: Add all + public AccessPolicyImpl forServicePrincipal(String servicePrincipalName) { + this.servicePrincipalName = servicePrincipalName; return this; } + @Override + public AccessPolicyImpl allowKeyAllPermissions() { + return allowKeyPermissions(KeyPermissions.ALL); + } + @Override public AccessPolicyImpl disallowKeyAllPermissions() { initializeKeyPermissions(); @@ -170,8 +186,7 @@ public AccessPolicyImpl disallowKeyPermissions(List permissions) @Override public AccessPolicyImpl allowSecretAllPermissions() { - // TODO: add all - return null; + return allowSecretPermissions(SecretPermissions.ALL); } @Override diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index d0e8da09b3867..b3c22caef6721 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -6,6 +6,10 @@ package com.microsoft.azure.management.keyvault.implementation; +import com.microsoft.azure.ParallelServiceCall; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; import com.microsoft.azure.management.keyvault.Sku; @@ -20,6 +24,7 @@ import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -38,10 +43,19 @@ class VaultImpl Vault.Definition, Vault.Update { private VaultsInner client; + private GraphRbacManager graphRbacManager; + private List accessPolicies; - protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager) { + protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.client = client; + this.graphRbacManager = graphRbacManager; + this.accessPolicies = new ArrayList<>(); + if (innerObject != null && innerObject.properties() != null && innerObject.properties().accessPolicies() != null) { + for (AccessPolicyEntry entry : innerObject.properties().accessPolicies()) { + this.accessPolicies.add(new AccessPolicyImpl(entry, this)); + } + } } @Override @@ -70,17 +84,8 @@ public Sku sku() { @Override public List accessPolicies() { - if (inner().properties() == null) { - return null; - } - if (inner().properties().accessPolicies() == null) { - return null; - } - List accessPolicies = new ArrayList<>(); - for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { - accessPolicies.add(new AccessPolicyImpl(entry, this)); - } - return accessPolicies; + AccessPolicy[] array = new AccessPolicy[accessPolicies.size()]; + return Arrays.asList(accessPolicies.toArray(array)); } @Override @@ -109,27 +114,24 @@ public Boolean enabledForTemplateDeployment() { @Override public VaultImpl withEmptyAccessPolicy() { - if (inner().properties() == null) { - inner().withProperties(new VaultProperties()); - } - inner().properties().withAccessPolicies(new ArrayList()); + this.accessPolicies = new ArrayList<>(); return this; } @Override - public Update withoutAccessPolicy(String objectId) { - return null; + public VaultImpl withoutAccessPolicy(String objectId) { + for (AccessPolicyImpl entry : this.accessPolicies) { + if (entry.objectId().toString().equals(objectId)) { + accessPolicies.remove(entry); + break; + } + } + return this; } @Override public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { - if (inner().properties() == null) { - inner().withProperties(new VaultProperties()); - } - if (inner().properties().accessPolicies() == null) { - inner().properties().withAccessPolicies(new ArrayList()); - } - inner().properties().accessPolicies().add(accessPolicy.inner()); + accessPolicies.add((AccessPolicyImpl) accessPolicy); return this; } @@ -140,15 +142,9 @@ public AccessPolicyImpl defineAccessPolicy() { @Override public AccessPolicyImpl updateAccessPolicy(String objectId) { - if (inner().properties() == null) { - return null; - } - if (inner().properties().accessPolicies() == null) { - return null; - } - for (AccessPolicyEntry entry : inner().properties().accessPolicies()) { + for (AccessPolicyImpl entry : this.accessPolicies) { if (entry.objectId().toString().equals(objectId)) { - return new AccessPolicyImpl(entry, this); + return entry; } } throw new NoSuchElementException(String.format("Identity %s not found in the access policies.", objectId)); @@ -211,27 +207,84 @@ public ServiceCall applyAsync(ServiceCallback callback) { @Override public ServiceCall createResourceAsync(final ServiceCallback serviceCallback) { - VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); - parameters.withLocation(regionName()); - parameters.withProperties(inner().properties()); - parameters.withTags(inner().getTags()); + final ServiceCall serviceCall = new ServiceCall(null); final VaultImpl self = this; - return client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { + serviceCall.newCall(populateAccessPolicies(new ServiceCallback() { @Override public void failure(Throwable t) { serviceCallback.failure(t); + serviceCall.failure(t); } @Override - public void success(ServiceResponse result) { - setInner(result.getBody()); - serviceCallback.success(new ServiceResponse(self, result.getResponse())); + public void success(ServiceResponse result) { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + serviceCall.newCall(client.createOrUpdateAsync(resourceGroupName(), name(), parameters, new ServiceCallback() { + @Override + public void failure(Throwable t) { + serviceCallback.failure(t); + serviceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + setInner(result.getBody()); + ServiceResponse clientResponse = new ServiceResponse(self, result.getResponse()); + serviceCallback.success(clientResponse); + serviceCall.success(clientResponse); + } + }).getCall()); + } + }).getCall()); + return serviceCall; + } + + private ParallelServiceCall populateAccessPolicies(final ServiceCallback callback) { + final ParallelServiceCall parallelServiceCall = new ParallelServiceCall(); + for (final AccessPolicyImpl accessPolicy : accessPolicies) { + if (accessPolicy.objectId() == null) { + if (accessPolicy.userPrincipalName != null) { + parallelServiceCall.addCall(graphRbacManager.users().getByUserPrincipalNameAsync(accessPolicy.userPrincipalName, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + parallelServiceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + callback.success(null); + accessPolicy.forUser(result.getBody()); + } + })); + } else if (accessPolicy.servicePrincipalName != null) { + parallelServiceCall.addCall(graphRbacManager.servicePrincipals().getByServicePrincipalNameAsync(accessPolicy.servicePrincipalName, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + parallelServiceCall.failure(t); + } + + @Override + public void success(ServiceResponse result) { + callback.success(null); + accessPolicy.forServicePrincipal(result.getBody()); + } + })); + } else { + throw new IllegalArgumentException("Access policy must specify object ID."); + } } - }); + } + return parallelServiceCall; } @Override public VaultImpl createResource() throws Exception { + populateAccessPolicies(null).get(); VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); parameters.withLocation(regionName()); parameters.withProperties(inner().properties()); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java index ebda765beb04a..e35af2c9c3986 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -84,7 +84,8 @@ protected VaultImpl wrapModel(String name) { name, inner, this.innerCollection, - super.myManager); + super.myManager, + graphRbacManager); } @Override @@ -93,6 +94,7 @@ protected VaultImpl wrapModel(VaultInner vaultInner) { vaultInner.name(), vaultInner, this.innerCollection, - super.myManager); + super.myManager, + graphRbacManager); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 0cfbfd7012133..dd1c84c1c177d 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -8,10 +8,10 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; +import com.microsoft.rest.credentials.TokenCredentials; import okhttp3.logging.HttpLoggingInterceptor; /** @@ -21,21 +21,24 @@ public abstract class KeyVaultManagementTestBase { protected static ResourceManager resourceManager; protected static GraphRbacManager graphRbacManager; protected static KeyVaultManager keyVaultManager; - protected static ApplicationTokenCredentials credentials; protected static void createClients() { - credentials = new ApplicationTokenCredentials( - System.getenv("client-id"), - System.getenv("domain"), - System.getenv("secret"), - null); - - ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( - System.getenv("client-id"), - System.getenv("domain"), - System.getenv("secret"), - "https://graph.windows.net/", - null); +// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( +// System.getenv("client-id"), +// System.getenv("domain"), +// System.getenv("secret"), +// null); + TokenCredentials credentials = new TokenCredentials("Bearer", + "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlliUkFRUlljRV9tb3RXVkpLSHJ3TEJiZF85cyIsImtpZCI6IlliUkFRUlljRV9tb3RXVkpLSHJ3TEJiZF85cyJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC83MmY5ODhiZi04NmYxLTQxYWYtOTFhYi0yZDdjZDAxMWRiNDcvIiwiaWF0IjoxNDcwNjk4Nzg1LCJuYmYiOjE0NzA2OTg3ODUsImV4cCI6MTQ3MDcwMjY4NSwiX2NsYWltX25hbWVzIjp7Imdyb3VwcyI6InNyYzEifSwiX2NsYWltX3NvdXJjZXMiOnsic3JjMSI6eyJlbmRwb2ludCI6Imh0dHBzOi8vZ3JhcGgud2luZG93cy5uZXQvNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3L3VzZXJzLzc5NGI4MzQ3LWMzOTgtNGZkOC1iNTU3LTM3YjYwOTQ2ZTgzMC9nZXRNZW1iZXJPYmplY3RzIn19LCJhY3IiOiIxIiwiYW1yIjpbInB3ZCIsIm1mYSJdLCJhcHBpZCI6IjA0YjA3Nzk1LThkZGItNDYxYS1iYmVlLTAyZjllMWJmN2I0NiIsImFwcGlkYWNyIjoiMCIsImVfZXhwIjo3MjAwLCJmYW1pbHlfbmFtZSI6Ikx1IiwiZ2l2ZW5fbmFtZSI6IkppYW5naGFvIiwiaW5fY29ycCI6InRydWUiLCJpcGFkZHIiOiIxNjcuMjIwLjAuMTI1IiwibmFtZSI6IkppYW5naGFvIEx1Iiwib2lkIjoiNzk0YjgzNDctYzM5OC00ZmQ4LWI1NTctMzdiNjA5NDZlODMwIiwib25wcmVtX3NpZCI6IlMtMS01LTIxLTIxMjc1MjExODQtMTYwNDAxMjkyMC0xODg3OTI3NTI3LTE0Njc4ODM4IiwicHVpZCI6IjEwMDM3RkZFOEE0Qzg1RTkiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJzdWIiOiI3SFB4WXhMNkJvU1J2V3QwMHdzYkh6VTk3U3AyMTRlLTlnUmJ0ekFJVUZvIiwidGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3IiwidW5pcXVlX25hbWUiOiJqaWFuZ2hsdUBtaWNyb3NvZnQuY29tIiwidXBuIjoiamlhbmdobHVAbWljcm9zb2Z0LmNvbSIsInZlciI6IjEuMCJ9.rffKiCvus0jtqRIALT-lyGJbd2bd-tnnBfIKXqLlcDaoPkQwXM-VY8mROhqReydtYUolri8vbIszvd_B1r1Cvq3q3b4U7OcPFiw8d9bqst6qr02kPFiHgbgAtBK_yAJmT8ckJVwScgG1oZGqeKFxWzOtfJKtau4zDQC6zGog0jDGQm_BobxvGqSDKkBE7E9v88YdAt-wiS9rt2ne1mmqFm5weRALLfK3nu9WyUmoHKRx-ywqDDXnh_sHRMJ-jkZ6LT_0uigwJHLGG3tCtl3wJ91gUx6Tantd1QMnsADUfYB-fUazQqvJ8A4Hcu3nqVN8D8ucw4OsupzN_G2kJUuy5A"); + +// ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( +// System.getenv("client-id"), +// System.getenv("domain"), +// System.getenv("secret"), +// "https://graph.windows.net/", +// null); + TokenCredentials graphCredentials = new TokenCredentials("Bearer", + "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlliUkFRUlljRV9tb3RXVkpLSHJ3TEJiZF85cyIsImtpZCI6IlliUkFRUlljRV9tb3RXVkpLSHJ3TEJiZF85cyJ9.eyJhdWQiOiJodHRwczovL2dyYXBoLndpbmRvd3MubmV0LyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0Ny8iLCJpYXQiOjE0NzA2OTk0MTUsIm5iZiI6MTQ3MDY5OTQxNSwiZXhwIjoxNDcwNzAzMzE1LCJhY3IiOiIxIiwiYW1yIjpbInB3ZCIsIm1mYSJdLCJhcHBpZCI6IjA0YjA3Nzk1LThkZGItNDYxYS1iYmVlLTAyZjllMWJmN2I0NiIsImFwcGlkYWNyIjoiMCIsImVfZXhwIjo3MjAwLCJmYW1pbHlfbmFtZSI6Ikx1IiwiZ2l2ZW5fbmFtZSI6IkppYW5naGFvIiwiaW5fY29ycCI6InRydWUiLCJpcGFkZHIiOiIxNjcuMjIwLjAuMTI1IiwibmFtZSI6IkppYW5naGFvIEx1Iiwib2lkIjoiNzk0YjgzNDctYzM5OC00ZmQ4LWI1NTctMzdiNjA5NDZlODMwIiwib25wcmVtX3NpZCI6IlMtMS01LTIxLTIxMjc1MjExODQtMTYwNDAxMjkyMC0xODg3OTI3NTI3LTE0Njc4ODM4IiwicHVpZCI6IjEwMDM3RkZFOEE0Qzg1RTkiLCJzY3AiOiI2MmU5MDM5NC02OWY1LTQyMzctOTE5MC0wMTIxNzcxNDVlMTAiLCJzdWIiOiJHbl84X2xySnIxaTJDT1FpRmZHV0FXbS1FTndCME9DNFVaZ0tXRUhDVVpFIiwidGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3IiwidW5pcXVlX25hbWUiOiJqaWFuZ2hsdUBtaWNyb3NvZnQuY29tIiwidXBuIjoiamlhbmdobHVAbWljcm9zb2Z0LmNvbSIsInZlciI6IjEuMCJ9.plHfVGR41eREXMJbYwcHgpYJLJH5gf-25FOOKFPcdZMbGLp2sFS1Yu4lv1RTN8aKQ6ZBO-aeBoStgj4rVmd4GJDsJY_EBST8LFtAY1jK5Ds437nlMdVDeL1OPE5ecUy_KOVzjFTJFEYl_sQBsgAevUucsqDccdNxHZzwZSYeJzQ3vYtrapKsE4lsVwZQYXXjosna_f6gy65r-hsl4fnYmVnHmpey5PtMf5byNbuzutsSuf77zMn5bKUPruteK7pzzGMDsdAFY2v9a17C0_jbqfcQh7c7RDZTsHRN8ueUR9VZ5VXLs1ixWFY3M8cLSQa4Nxxgk7XL2mzQ3qTQx97NSg"); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) @@ -50,6 +53,6 @@ protected static void createClients() { .authenticate(graphCredentials, System.getenv("domain")); keyVaultManager = KeyVaultManager - .authenticate(restClient, System.getenv("subscription-id"), graphCredentials.getDomain()); + .authenticate(restClient, System.getenv("domain"), System.getenv("subscription-id")); } } diff --git a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java index 22185e80d0c38..9b42d82a43f73 100644 --- a/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/java/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,8 +6,6 @@ package com.microsoft.azure.management.keyvault; -import com.microsoft.azure.management.graphrbac.ServicePrincipal; -import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; import org.junit.Assert; @@ -33,13 +31,12 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { // CREATE - ServicePrincipal sp = graphRbacManager.servicePrincipals().getByServicePrincipalName("app-123"); - User user = graphRbacManager.users().getByUserPrincipalName("azuresdk@outlook.com"); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) .defineAccessPolicy() - .forServicePrincipal(sp) + .forServicePrincipal("http://nativeapp") + .allowKeyPermissions(KeyPermissions.LIST) .allowSecretAllPermissions() .attach() .create(); @@ -65,12 +62,9 @@ public void canCRUDVault() throws Exception { .apply(); vault.update() .defineAccessPolicy() - .forUser(user) + .forServicePrincipal("http://nativeapp") .allowKeyAllPermissions() .attach() .apply(); - vault.update() - .withoutAccessPolicy(sp.objectId()) - .apply(); } } diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java new file mode 100644 index 0000000000000..316384152031b --- /dev/null +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java @@ -0,0 +1,50 @@ +package com.microsoft.azure; + +import com.microsoft.rest.ServiceCall; + +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Type represents a set of REST calls running possibly in parallel. + */ +public class ParallelServiceCall extends ServiceCall { + private ConcurrentLinkedQueue> serviceCalls; + + /** + * Creates a ParallelServiceCall. + */ + public ParallelServiceCall() { + super(null); + this.serviceCalls = new ConcurrentLinkedQueue<>(); + } + + /** + * Cancels all the service calls currently executing. + */ + public void cancel() { + for (ServiceCall call : this.serviceCalls) { + call.cancel(); + } + } + + /** + * @return true if the call has been canceled; false otherwise. + */ + public boolean isCancelled() { + for (ServiceCall call : this.serviceCalls) { + if (!call.isCanceled()) { + return false; + } + } + return true; + } + + /** + * Add a call to the list of parallel calls. + * + * @param call the call + */ + public void addCall(ServiceCall call) { + this.serviceCalls.add(call); + } +} diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java index f3a4b231c8e2c..62b34461bac7f 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java @@ -11,8 +11,6 @@ import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import java.util.concurrent.ConcurrentLinkedQueue; - /** * The base implementation of TaskGroup interface. * @@ -22,7 +20,7 @@ public abstract class TaskGroupBase> implements TaskGroup { private DAGraph> dag; - private ParallelServiceCall parallelServiceCall; + private ParallelServiceCall parallelServiceCall; /** * Creates TaskGroupBase. @@ -125,48 +123,4 @@ public void success(ServiceResponse result) { }; } - /** - * Type represents a set of REST calls running possibly in parallel. - */ - private class ParallelServiceCall extends ServiceCall { - private ConcurrentLinkedQueue> serviceCalls; - - /** - * Creates a ParallelServiceCall. - */ - ParallelServiceCall() { - super(null); - this.serviceCalls = new ConcurrentLinkedQueue<>(); - } - - /** - * Cancels all the service calls currently executing. - */ - public void cancel() { - for (ServiceCall call : this.serviceCalls) { - call.cancel(); - } - } - - /** - * @return true if the call has been canceled; false otherwise. - */ - public boolean isCancelled() { - for (ServiceCall call : this.serviceCalls) { - if (!call.isCanceled()) { - return false; - } - } - return true; - } - - /** - * Add a call to the list of parallel calls. - * - * @param call the call - */ - private void addCall(ServiceCall call) { - this.serviceCalls.add(call); - } - } }