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 3dd765e1d3..3b6b162794 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 @@ -121,7 +121,7 @@ public ApplicationTokenCredentials withDefaultSubscriptionId(String subscription public static ApplicationTokenCredentials fromFile(File credentialsFile) throws IOException { // Set defaults Properties authSettings = new Properties(); - authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.authenticationEndpoint()); + authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.activeDirectoryEndpoint()); authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.resourceManagerEndpoint()); authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.managementEndpoint()); authSettings.put(CredentialSettings.GRAPH_URL.toString(), AzureEnvironment.AZURE.graphEndpoint()); @@ -144,12 +144,13 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws clientId, tenantId, clientKey, - new AzureEnvironment( - authUrl, - mgmtUri, - baseUrl, - graphUrl) - ).withDefaultSubscriptionId(defaultSubscriptionId); + new AzureEnvironment(new HashMap() {{ + put(AzureEnvironment.Endpoint.ACTIVE_DIRECTORY.toString(), authUrl); + put(AzureEnvironment.Endpoint.MANAGEMENT.toString(), mgmtUri); + put(AzureEnvironment.Endpoint.RESOURCE_MANAGER.toString(), baseUrl); + put(AzureEnvironment.Endpoint.GRAPH.toString(), graphUrl); + }} + )).withDefaultSubscriptionId(defaultSubscriptionId); } /** @@ -181,7 +182,7 @@ public synchronized String getToken(String resource) throws IOException { } private AuthenticationResult acquireAccessToken(String resource) throws IOException { - String authorityUrl = this.environment().authenticationEndpoint() + this.domain(); + String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor); try { 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 149af8b14c..5801fe50a7 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 @@ -49,7 +49,7 @@ public UserTokenCredentials(String clientId, String domain, String username, Str this.username = username; this.password = password; this.tokens = new ConcurrentHashMap<>(); - this.refreshTokenClient = new RefreshTokenClient(environment.authenticationEndpoint()); + this.refreshTokenClient = new RefreshTokenClient(environment.activeDirectoryEndpoint()); } /** @@ -107,7 +107,7 @@ public synchronized String getToken(String resource) throws IOException { } AuthenticationResult acquireNewAccessToken(String resource) throws IOException { - String authorityUrl = this.environment().authenticationEndpoint() + this.domain(); + String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor); try { 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 f7a44e8c64..83f949822d 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 @@ -9,124 +9,276 @@ import com.microsoft.rest.protocol.Environment; import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; /** * An instance of this class describes an environment in Azure. */ public final class AzureEnvironment implements Environment { + /** the management portal URL. */ + private final String portalUrl; + /** the publish settings file URL. */ + private final String publishingProfileUrl; + /** the management service endpoint. */ + private final String managementEndpointUrl; + /** the resource management endpoint. */ + private final String resourceManagerEndpointUrl; + /** the sql server management endpoint for mobile commands. */ + private final String sqlManagementEndpointUrl; + /** the dns suffix for sql servers. */ + private final String sqlServerHostnameSuffix; + /** the Active Directory login endpoint. */ + private final String activeDirectoryEndpointUrl; + /** The resource ID to obtain AD tokens for. */ + private final String activeDirectoryResourceId; + /** the template gallery endpoint. */ + private final String galleryEndpointUrl; + /** the Active Directory resource ID. */ + private final String activeDirectoryGraphResourceId; + /** the Active Directory api version. */ + private final String activeDirectoryGraphApiVersion; + /** the endpoint suffix for storage accounts. */ + private final String storageEndpointSuffix; + /** the keyvault service dns suffix. */ + private final String keyVaultDnsSuffix; + /** the data lake store filesystem service dns suffix. */ + private final String azureDataLakeStoreFileSystemEndpointSuffix; + /** the data lake analytics job and catalog service dns suffix. */ + private final String azureDataLakeAnalyticsCatalogAndJobEndpointSuffix; + /** - * Base URL for calls to Azure management API. + * Initializes an instance of AzureEnvironment class. + * + * @param endpoints a map storing all the endpoint info */ - private final String resourceManagerEndpoint; + public AzureEnvironment(Map endpoints) { + this.portalUrl = endpoints.get("portalUrl"); + this.publishingProfileUrl = endpoints.get("publishingProfileUrl"); + this.managementEndpointUrl = endpoints.get("managementEndpointUrl"); + this.resourceManagerEndpointUrl = endpoints.get("resourceManagerEndpointUrl"); + this.sqlManagementEndpointUrl = endpoints.get("sqlManagementEndpointUrl"); + this.sqlServerHostnameSuffix = endpoints.get("sqlServerHostnameSuffix"); + this.activeDirectoryEndpointUrl = endpoints.get("activeDirectoryEndpointUrl"); + this.activeDirectoryResourceId = endpoints.get("activeDirectoryResourceId"); + this.galleryEndpointUrl = endpoints.get("galleryEndpointUrl"); + this.activeDirectoryGraphResourceId = endpoints.get("activeDirectoryGraphResourceId"); + this.activeDirectoryGraphApiVersion = endpoints.get("activeDirectoryGraphApiVersion"); + this.storageEndpointSuffix = endpoints.get("storageEndpointSuffix"); + this.keyVaultDnsSuffix = endpoints.get("keyVaultDnsSuffix"); + this.azureDataLakeStoreFileSystemEndpointSuffix = endpoints.get("azureDataLakeStoreFileSystemEndpointSuffix"); + this.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix = endpoints.get("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix"); + } /** - * ActiveDirectory Endpoint for the authentications. + * Provides the settings for authentication with Azure. */ - private final String authenticationEndpoint; + public static final AzureEnvironment AZURE = new AzureEnvironment(new HashMap() {{ + put("portalUrl", "http://go.microsoft.com/fwlink/?LinkId=254433"); + put("publishingProfileUrl", "http://go.microsoft.com/fwlink/?LinkId=254432"); + put("managementEndpointUrl", "https://management.core.windows.net"); + put("resourceManagerEndpointUrl", "https://management.azure.com/"); + put("sqlManagementEndpointUrl", "https://management.core.windows.net:8443/"); + put("sqlServerHostnameSuffix", ".database.windows.net"); + put("galleryEndpointUrl", "https://gallery.azure.com/"); + put("activeDirectoryEndpointUrl", "https://login.microsoftonline.com/"); + put("activeDirectoryResourceId", "https://management.core.windows.net/"); + put("activeDirectoryGraphResourceId", "https://graph.windows.net/"); + put("activeDirectoryGraphApiVersion", "2013-04-05"); + put("storageEndpointSuffix", ".core.windows.net"); + put("keyVaultDnsSuffix", ".vault.azure.net"); + put("azureDataLakeStoreFileSystemEndpointSuffix", "azuredatalakestore.net"); + put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "azuredatalakeanalytics.net"); + }}); /** - * Base URL for calls to service management and authentications to Active Directory. + * Provides the settings for authentication with Azure China. */ - private final String managementEndpoint; + public static final AzureEnvironment AZURE_CHINA = new AzureEnvironment(new HashMap() {{ + put("portalUrl", "http://go.microsoft.com/fwlink/?LinkId=301902"); + put("publishingProfileUrl", "http://go.microsoft.com/fwlink/?LinkID=301774"); + put("managementEndpointUrl", "https://management.core.chinacloudapi.cn"); + put("resourceManagerEndpointUrl", "https://management.chinacloudapi.cn"); + put("sqlManagementEndpointUrl", "https://management.core.chinacloudapi.cn:8443/"); + put("sqlServerHostnameSuffix", ".database.chinacloudapi.cn"); + put("galleryEndpointUrl", "https://gallery.chinacloudapi.cn/"); + put("activeDirectoryEndpointUrl", "https://login.chinacloudapi.cn/"); + put("activeDirectoryResourceId", "https://management.core.chinacloudapi.cn/"); + put("activeDirectoryGraphResourceId", "https://graph.chinacloudapi.cn/"); + put("activeDirectoryGraphApiVersion", "2013-04-05"); + put("storageEndpointSuffix", ".core.chinacloudapi.cn"); + put("keyVaultDnsSuffix", ".vault.azure.cn"); + // TODO: add dns suffixes for the china cloud for datalake store and datalake analytics once they are defined. + put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A"); + put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/A"); + }}); /** - * Base URL for calls to graph API. + * Provides the settings for authentication with Azure US Government. */ - private final String graphEndpoint; + public static final AzureEnvironment AZURE_US_GOVERNMENT = new AzureEnvironment(new HashMap() {{ + put("portalUrl", "https://manage.windowsazure.us"); + put("publishingProfileUrl", "https://manage.windowsazure.us/publishsettings/index"); + put("managementEndpointUrl", "https://management.core.usgovcloudapi.net"); + put("resourceManagerEndpointUrl", "https://management.usgovcloudapi.net"); + put("sqlManagementEndpointUrl", "https://management.core.usgovcloudapi.net:8443/"); + put("sqlServerHostnameSuffix", ".database.usgovcloudapi.net"); + put("galleryEndpointUrl", "https://gallery.usgovcloudapi.net/"); + put("activeDirectoryEndpointUrl", "https://login-us.microsoftonline.com/"); + put("activeDirectoryResourceId", "https://management.core.usgovcloudapi.net/"); + put("activeDirectoryGraphResourceId", "https://graph.windows.net/"); + put("activeDirectoryGraphApiVersion", "2013-04-05"); + put("storageEndpointSuffix", ".core.usgovcloudapi.net"); + put("keyVaultDnsSuffix", ".vault.usgovcloudapi.net"); + // TODO: add dns suffixes for the US government for datalake store and datalake analytics once they are defined. + put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A"); + put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/A"); + }}); /** - * Initializes an instance of AzureEnvironment class. - * - * @param authenticationEndpoint ActiveDirectory Endpoint for the Azure 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. + * Provides the settings for authentication with Azure Germany. + */ + public static final AzureEnvironment AZURE_GERMANY = new AzureEnvironment(new HashMap() {{ + put("portalUrl", "http://portal.microsoftazure.de/"); + put("publishingProfileUrl", "https://manage.microsoftazure.de/publishsettings/index"); + put("managementEndpointUrl", "https://management.core.cloudapi.de"); + put("resourceManagerEndpointUrl", "https://management.microsoftazure.de"); + put("sqlManagementEndpointUrl", "https://management.core.cloudapi.de:8443/"); + put("sqlServerHostnameSuffix", ".database.cloudapi.de"); + put("galleryEndpointUrl", "https://gallery.cloudapi.de/"); + put("activeDirectoryEndpointUrl", "https://login.microsoftonline.de/"); + put("activeDirectoryResourceId", "https://management.core.cloudapi.de/"); + put("activeDirectoryGraphResourceId", "https://graph.cloudapi.de/"); + put("activeDirectoryGraphApiVersion", "2013-04-05"); + put("storageEndpointSuffix", ".core.cloudapi.de"); + put("keyVaultDnsSuffix", ".vault.microsoftazure.de"); + // TODO: add dns suffixes for the US government for datalake store and datalake analytics once they are defined. + put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A"); + put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/"); + }}); + + /** + * @return the management portal URL. */ - public AzureEnvironment( - String authenticationEndpoint, - String managementEndpoint, - String resourceManagerEndpoint, - String graphEndpoint) { - this.authenticationEndpoint = authenticationEndpoint; - this.managementEndpoint = managementEndpoint; - this.resourceManagerEndpoint = resourceManagerEndpoint; - this.graphEndpoint = graphEndpoint; + public String portal() { + return portalUrl; } /** - * Provides the settings for authentication with Azure. + * @return the publish settings file URL. */ - public static final AzureEnvironment AZURE = new AzureEnvironment( - "https://login.microsoftonline.com/", - "https://management.core.windows.net/", - "https://management.azure.com/", - "https://graph.windows.net/"); + public String publishingProfile() { + return publishingProfileUrl; + } /** - * Provides the settings for authentication with Azure China. + * @return the management service endpoint. */ - public static final AzureEnvironment AZURE_CHINA = new AzureEnvironment( - "https://login.chinacloudapi.cn/", - "https://management.core.chinacloudapi.cn/", - "https://management.chinacloudapi.cn/", - "https://graph.chinacloudapi.cn/"); + public String managementEndpoint() { + return managementEndpointUrl; + } /** - * Provides the settings for authentication with Azure US Government. + * @return the resource management endpoint. */ - public static final AzureEnvironment AZURE_US_GOVERNMENT = new AzureEnvironment( - "https://login.microsoftonline.com/", - "https://management.core.usgovcloudapi.net/", - "https://management.usgovcloudapi.net/", - "https://graph.windows.net/"); + public String resourceManagerEndpoint() { + return resourceManagerEndpointUrl; + } /** - * Provides the settings for authentication with Azure Germany. + * @return the sql server management endpoint for mobile commands. */ - public static final AzureEnvironment AZURE_GERMANY = new AzureEnvironment( - "https://login.microsoftonline.de/", - "https://management.core.cloudapi.de/", - "https://management.microsoftazure.de/", - "https://graph.cloudapi.de/"); + public String sqlManagementEndpoint() { + return sqlManagementEndpointUrl; + } /** - * Gets the base URL of the management service. - * - * @return the Base URL for the management service. + * @return the dns suffix for sql servers. */ - public String resourceManagerEndpoint() { - return this.resourceManagerEndpoint; + public String sqlServerHostnameSuffix() { + return sqlServerHostnameSuffix; } /** - * @return the ActiveDirectory Endpoint for the Azure Environment. + * @return the Active Directory login endpoint. */ - public String authenticationEndpoint() { - return authenticationEndpoint; + public String activeDirectoryEndpoint() { + return activeDirectoryEndpointUrl; } /** - * @return the Azure Resource Manager endpoint for the environment. + * @return The resource ID to obtain AD tokens for. */ - public String managementEndpoint() { - return managementEndpoint; + public String activeDirectoryResourceId() { + return activeDirectoryResourceId; } /** - * @return the Graph API endpoint. + * @return the template gallery endpoint. + */ + public String galleryEndpoint() { + return galleryEndpointUrl; + } + + /** + * @return the Active Directory resource ID. */ public String graphEndpoint() { - return graphEndpoint; + return activeDirectoryGraphResourceId; } + /** + * @return the Active Directory api version. + */ + public String activeDirectoryGraphApiVersion() { + return activeDirectoryGraphApiVersion; + } + + /** + * @return the endpoint suffix for storage accounts. + */ + public String storageEndpointSuffix() { + return storageEndpointSuffix; + } + + /** + * @return the keyvault service dns suffix. + */ + public String keyVaultDnsSuffix() { + return keyVaultDnsSuffix; + } + + /** + * @return the data lake store filesystem service dns suffix. + */ + public String azureDataLakeStoreFileSystemEndpointSuffix() { + return azureDataLakeStoreFileSystemEndpointSuffix; + } + + /** + * @return the data lake analytics job and catalog service dns suffix. + */ + public String azureDataLakeAnalyticsCatalogAndJobEndpointSuffix() { + return azureDataLakeAnalyticsCatalogAndJobEndpointSuffix; + } + + /** * The enum representing available endpoints in an environment. */ public enum Endpoint implements Environment.Endpoint { /** Azure Resource Manager endpoint. */ - RESOURCE_MANAGER("resourceManagerEndpoint"), + RESOURCE_MANAGER("resourceManagerEndpointUrl"), /** Azure Active Directory Graph APIs endpoint. */ - GRAPH("graphEndpoint"); + GRAPH("activeDirectoryGraphResourceId"), + /** Azure SQL endpoint. */ + SQL("sqlManagementEndpointUrl"), + /** Azure Gallery endpoint. */ + GALLERY("galleryEndpointUrl"), + /** Active Directory authentication endpoint. */ + ACTIVE_DIRECTORY("activeDirectoryEndpointUrl"), + /** Azure management endpoint. */ + MANAGEMENT("managementEndpointUrl"); private String field;