Skip to content

Commit

Permalink
enabling Azure.authenticate(File).withDefaultSubscription() based on …
Browse files Browse the repository at this point in the history
…the subscription provided in the file
  • Loading branch information
unknown authored and unknown committed May 12, 2016
1 parent daacda8 commit 5e2de11
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class ApplicationTokenCredentials extends TokenCredentials {
private AzureEnvironment environment;
/** The current authentication result. */
private AuthenticationResult authenticationResult;

/** The default subscription to use, if any */
private String defaultSubscription;

/**
* Initializes a new instance of the UserTokenCredentials.
*
Expand Down Expand Up @@ -80,7 +82,18 @@ public String toString() {
}
}


/**
* @return The default subscription ID, if any
*/
public String defaultSubscriptionId() {
return defaultSubscription;
}

ApplicationTokenCredentials withDefaultSubscriptionId(String subscriptionId) {
this.defaultSubscription = subscriptionId;
return this;
}

/**
* Initializes the credentials based on the provided credentials file
* @param credentialsFile A file with credentials, using the standard Java properties format
Expand Down Expand Up @@ -113,7 +126,8 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
final String mgmtUri = authSettings.getProperty(CredentialSettings.MANAGEMENT_URI.toString());
final String authUrl = authSettings.getProperty(CredentialSettings.AUTH_URL.toString());
final String baseUrl = authSettings.getProperty(CredentialSettings.BASE_URL.toString());

final String defaultSubscriptionId = authSettings.getProperty(CredentialSettings.SUBSCRIPTION_ID.toString());

return new ApplicationTokenCredentials(
clientId,
tenantId,
Expand All @@ -123,7 +137,7 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
mgmtUri,
true,
baseUrl)
);
).withDefaultSubscriptionId(defaultSubscriptionId);
}


Expand Down Expand Up @@ -153,7 +167,7 @@ public String getDomain() {
public String getSecret() {
return secret;
}

/**
* Gets the Azure environment to authenticate with.
*
Expand Down

0 comments on commit 5e2de11

Please sign in to comment.