From d5a3639de1018c0eeaf00d81a9990ce2bd174043 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 1 Aug 2016 10:30:20 -0700 Subject: [PATCH 1/3] Add graph tests --- .../ApplicationTokenCredentials.java | 28 +++++++++++++++- .../credentials/UserTokenCredentials.java | 32 ++++++++++++++++++- .../com/microsoft/azure/AzureEnvironment.java | 2 +- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index 384ab3f767..abe3a65c9b 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -24,6 +24,8 @@ * Token based credentials for use with a REST Service Client. */ public class ApplicationTokenCredentials extends TokenCredentials { + /** The endpoint of the target resource. */ + private String resourceEndpoint; /** The active directory application client id. */ private String clientId; /** The tenant or domain the containing the application. */ @@ -56,6 +58,30 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret } else { this.environment = environment; } + this.resourceEndpoint = this.environment.getTokenAudience(); + } + + /** + * Initializes a new instance of the UserTokenCredentials. + * + * @param clientId the active directory application client id. + * @param domain the domain or tenant id containing this application. + * @param secret the authentication secret for the application. + * @param resourceEndpoint the endpoint of the target resource. + * @param environment the Azure environment to authenticate with. + * If null is provided, AzureEnvironment.AZURE will be used. + */ + public ApplicationTokenCredentials(String clientId, String domain, String secret, String resourceEndpoint, AzureEnvironment environment) { + super(null, null); // defer token acquisition + this.clientId = clientId; + this.domain = domain; + this.secret = secret; + this.resourceEndpoint = resourceEndpoint; + if (environment == null) { + this.environment = AzureEnvironment.AZURE; + } else { + this.environment = environment; + } } /** @@ -212,7 +238,7 @@ private void acquireAccessToken() throws IOException { AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { authenticationResult = context.acquireToken( - this.getEnvironment().getTokenAudience(), + this.resourceEndpoint, new ClientCredential(this.getClientId(), this.getSecret()), null).get(); } catch (Exception e) { diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index 60d6bdb3c0..c37479771a 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -21,6 +21,8 @@ * Token based credentials for use with a REST Service Client. */ public class UserTokenCredentials extends TokenCredentials { + /** The endpoint of the target resource. */ + private String resourceEndpoint; /** The Active Directory application client id. */ private String clientId; /** The domain or tenant id containing this application. */ @@ -59,6 +61,34 @@ public UserTokenCredentials(String clientId, String domain, String username, Str } else { this.environment = environment; } + this.resourceEndpoint = this.environment.getTokenAudience(); + } + + /** + * Initializes a new instance of the UserTokenCredentials. + * + * @param clientId the active directory application client id. + * @param domain the domain or tenant id containing this application. + * @param username the user name for the Organization Id account. + * @param password the password for the Organization Id account. + * @param clientRedirectUri the Uri where the user will be redirected after authenticating with AD. + * @param resourceEndpoint the endpoint of the target resource. + * @param environment the Azure environment to authenticate with. + * If null is provided, AzureEnvironment.AZURE will be used. + */ + public UserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, String resourceEndpoint, AzureEnvironment environment) { + super(null, null); // defer token acquisition + this.clientId = clientId; + this.domain = domain; + this.username = username; + this.password = password; + this.clientRedirectUri = clientRedirectUri; + this.resourceEndpoint = resourceEndpoint; + if (environment == null) { + this.environment = AzureEnvironment.AZURE; + } else { + this.environment = environment; + } } /** @@ -136,7 +166,7 @@ private void acquireAccessToken() throws IOException { AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor()); try { authenticationResult = context.acquireToken( - this.getEnvironment().getTokenAudience(), + this.resourceEndpoint, this.getClientId(), this.getUsername(), this.getPassword(), diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index 04a6af99d9..897e29b622 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -56,7 +56,7 @@ public AzureEnvironment( * Provides the settings for authentication with Azure. */ public static final AzureEnvironment AZURE = new AzureEnvironment( - "https://login.windows.net/", + "https://login.microsoftonline.com/", "https://management.core.windows.net/", true, "https://management.azure.com/"); From 0a85d84aca2980038c955aaf311d942e62ee7345 Mon Sep 17 00:00:00 2001 From: anuchan Date: Sun, 4 Sep 2016 18:27:17 -0700 Subject: [PATCH 2/3] applyAsync on a root resource should create a dependency resource only if it is not already created and root resource always needs to be updated in this case --- .../com/microsoft/azure/TaskGroupBase.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java b/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java index 747f0273fa..6de2a3ab46 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java @@ -64,18 +64,31 @@ public Observable executeAsync() { final List> observables = new ArrayList<>(); while (nextNode != null) { final DAGNode thisNode = nextNode; - observables.add(nextNode.data().executeAsync() - .flatMap(new Func1>() { - @Override - public Observable call(T t) { - dag().reportedCompleted(thisNode); - if (dag().isRootNode(thisNode)) { - return Observable.just(t); - } else { + T cachedResult = nextNode.data().result(); + if (cachedResult != null && !this.dag().isRootNode(nextNode)) { + observables.add(Observable.just(cachedResult) + .flatMap(new Func1>() { + @Override + public Observable call(T t) { + dag().reportedCompleted(thisNode); return executeAsync(); } - } - })); + }) + ); + } else { + observables.add(nextNode.data().executeAsync() + .flatMap(new Func1>() { + @Override + public Observable call(T t) { + dag().reportedCompleted(thisNode); + if (dag().isRootNode(thisNode)) { + return Observable.just(t); + } else { + return executeAsync(); + } + } + })); + } nextNode = dag.getNext(); } return Observable.merge(observables); From 9be12ef2534e334e7629f966c62690d83d7e6b95 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 6 Sep 2016 16:57:19 -0700 Subject: [PATCH 3/3] Fix errors from merge --- .../src/main/java/com/microsoft/rest/ServiceCall.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java b/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java index 218a33f745..960a016b88 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java +++ b/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java @@ -136,7 +136,7 @@ protected void setSubscription(Subscription subscription) { * @param result the service response returned. * @return true if successfully reported; false otherwise. */ - public boolean success(ServiceResponse result) { + public boolean success(T result) { return set(result); }