Skip to content

Commit

Permalink
Add group & add graph endpoints to AzureEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Sep 13, 2016
1 parent 61de8e9 commit e6c05e1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
this.resourceEndpoint = this.environment.getManagementEndpoint();
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
Properties authSettings = new Properties();
authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.getAuthenticationEndpoint());
authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.getBaseUrl());
authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getTokenAudience());
authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getManagementEndpoint());

// Load the credentials from the file
FileInputStream credentialsFileStream = new FileInputStream(credentialsFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public UserTokenCredentials(String clientId, String domain, String username, Str
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
this.resourceEndpoint = this.environment.getManagementEndpoint();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ public final class AzureEnvironment {
/**
* Base URL for calls to Azure management API.
*/
private final String baseURL;
private final String resourceManagerEndpoint;

/**
* ActiveDirectory Endpoint for the Azure Environment.
* ActiveDirectory Endpoint for the authentications.
*/
private String authenticationEndpoint;

/**
* Token audience for an endpoint.
* Base URL for calls to service management and authentications to Active Directory.
*/
private String tokenAudience;
private String managementEndpoint;

/**
* Base URL for calls to graph API.
*/
private String graphEndpoint;

/**
* Determines whether the authentication endpoint should
Expand All @@ -36,20 +41,20 @@ public final class AzureEnvironment {
* Initializes an instance of AzureEnvironment class.
*
* @param authenticationEndpoint ActiveDirectory Endpoint for the Azure Environment.
* @param tokenAudience token audience for an endpoint.
* @param validateAuthority whether the authentication endpoint should
* be validated with Azure AD.
* @param baseUrl the base URL for the current environment.
* @param managementEndpoint token audience for an endpoint.
* @param resourceManagerEndpoint the base URL for the current environment.
* @param graphEndpoint the base URL for graph API.
*/
public AzureEnvironment(
String authenticationEndpoint,
String tokenAudience,
boolean validateAuthority,
String baseUrl) {
String managementEndpoint,
String resourceManagerEndpoint,
String graphEndpoint) {
this.authenticationEndpoint = authenticationEndpoint;
this.tokenAudience = tokenAudience;
this.validateAuthority = validateAuthority;
this.baseURL = baseUrl;
this.managementEndpoint = managementEndpoint;
this.resourceManagerEndpoint = resourceManagerEndpoint;
this.graphEndpoint = graphEndpoint;
this.validateAuthority = true;
}

/**
Expand All @@ -58,43 +63,43 @@ public AzureEnvironment(
public static final AzureEnvironment AZURE = new AzureEnvironment(
"https://login.microsoftonline.com/",
"https://management.core.windows.net/",
true,
"https://management.azure.com/");
"https://management.azure.com/",
"https://graph.windows.net/");

/**
* Provides the settings for authentication with Azure China.
*/
public static final AzureEnvironment AZURE_CHINA = new AzureEnvironment(
"https://login.chinacloudapi.cn/",
"https://management.core.chinacloudapi.cn/",
true,
"https://management.chinacloudapi.cn/");
"https://management.chinacloudapi.cn/",
"https://graph.chinacloudapi.cn/");

/**
* Provides the settings for authentication with Azure US Government.
*/
public static final AzureEnvironment AZURE_US_GOVERNMENT = new AzureEnvironment(
"https://login.microsoftonline.com/",
"https://management.core.usgovcloudapi.net/",
true,
"https://management.usgovcloudapi.net/");
"https://management.usgovcloudapi.net/",
"https://graph.windows.net/");

/**
* Provides the settings for authentication with Azure Germany.
*/
public static final AzureEnvironment AZURE_GERMANY = new AzureEnvironment(
"https://login.microsoftonline.de/",
"https://management.core.cloudapi.de/",
true,
"https://management.microsoftazure.de/");
"https://management.microsoftazure.de/",
"https://graph.cloudapi.de/");

/**
* Gets the base URL of the management service.
*
* @return the Base URL for the management service.
*/
public String getBaseUrl() {
return this.baseURL;
return this.resourceManagerEndpoint;
}

/**
Expand Down Expand Up @@ -122,8 +127,8 @@ public String getAuthenticationEndpoint() {
*
* @return the token audience for an endpoint.
*/
public String getTokenAudience() {
return tokenAudience;
public String getManagementEndpoint() {
return managementEndpoint;
}

/**
Expand All @@ -136,4 +141,15 @@ public String getTokenAudience() {
public boolean isValidateAuthority() {
return validateAuthority;
}

/**
* Sets whether the authentication endpoint should
* be validated with Azure AD.
*
* @param validateAuthority true if the authentication endpoint should
* be validated with Azure AD, false otherwise.
*/
public void setValidateAuthority(boolean validateAuthority) {
this.validateAuthority = validateAuthority;
}
}

0 comments on commit e6c05e1

Please sign in to comment.