Package com.microsoft.azure.maven.auth
Class AzureAuthHelperLegacy
- java.lang.Object
-
- com.microsoft.azure.maven.auth.AzureAuthHelperLegacy
-
public class AzureAuthHelperLegacy extends Object
Helper class to authenticate with Azure
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AzureAuthHelperLegacy(AuthConfiguration config)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidassureServerExist(org.apache.maven.settings.Server server, String serverId)Assure the server with specified id does exist in settings.xml.protected com.microsoft.azure.management.Azure.ConfigurableazureConfigure()protected com.microsoft.azure.credentials.ApplicationTokenCredentialsgetAppTokenCredentialsFromServer(org.apache.maven.settings.Server server)Get ApplicationTokenCredentials from server definition in Maven settings.xmlprotected com.microsoft.azure.management.Azure.AuthenticatedgetAuthObj()protected com.microsoft.azure.management.Azure.AuthenticatedgetAuthObjFromAzureCli()Get Authenticated object using authentication file from Azure CLI 2.0 Note: The integrated Azure CLI in Azure Cloud Shell does not have the accessToken.json, so we need to use MSI to authenticate in the Cloud Shell.protected com.microsoft.azure.management.Azure.AuthenticatedgetAuthObjFromFile(File authFile)Get Authenticated object using file.protected com.microsoft.azure.management.Azure.AuthenticatedgetAuthObjFromServerId(org.apache.maven.settings.Settings settings, String serverId)Get Authenticated object by referencing server definition in Maven settings.xmlcom.microsoft.azure.management.AzuregetAzureClient()private static com.google.gson.JsonArraygetAzureCliTokenList()protected com.microsoft.azure.AzureEnvironmentgetAzureEnvironment(String environment)protected com.microsoft.azure.credentials.ApplicationTokenCredentialsgetCredentialFromAzureCliWithServicePrincipal()Get Authenticated object from token file of Azure CLI 2.0 logged with Service Principal Note: This is a workaround for issue https://github.com/microsoft/azure-maven-plugins/issues/125private static com.google.gson.JsonObjectgetDefaultSubscriptionObject()protected com.microsoft.rest.LogLevelgetLogLevel()private static org.apache.maven.settings.ServergetServer(org.apache.maven.settings.Settings settings, String serverId)Get server credential from Maven settings by server Id.static StringgetSubscriptionOfCloudShell()private static StringgetValueFromServerConfiguration(org.apache.maven.settings.Server server, String key)Get string value from server configuration section in settings.xml.static booleanisInCloudShell()
-
-
-
Field Detail
-
CLIENT_ID
public static final String CLIENT_ID
- See Also:
- Constant Field Values
-
TENANT_ID
public static final String TENANT_ID
- See Also:
- Constant Field Values
-
KEY
public static final String KEY
- See Also:
- Constant Field Values
-
CERTIFICATE
public static final String CERTIFICATE
- See Also:
- Constant Field Values
-
CERTIFICATE_PASSWORD
public static final String CERTIFICATE_PASSWORD
- See Also:
- Constant Field Values
-
ENVIRONMENT
public static final String ENVIRONMENT
- See Also:
- Constant Field Values
-
CLOUD_SHELL_ENV_KEY
public static final String CLOUD_SHELL_ENV_KEY
- See Also:
- Constant Field Values
-
AUTH_WITH_SERVER_ID
public static final String AUTH_WITH_SERVER_ID
- See Also:
- Constant Field Values
-
AUTH_WITH_FILE
public static final String AUTH_WITH_FILE
- See Also:
- Constant Field Values
-
AUTH_WITH_AZURE_CLI
public static final String AUTH_WITH_AZURE_CLI
- See Also:
- Constant Field Values
-
AUTH_WITH_MSI
public static final String AUTH_WITH_MSI
- See Also:
- Constant Field Values
-
USE_KEY_TO_AUTH
public static final String USE_KEY_TO_AUTH
- See Also:
- Constant Field Values
-
USE_CERTIFICATE_TO_AUTH
public static final String USE_CERTIFICATE_TO_AUTH
- See Also:
- Constant Field Values
-
SERVER_ID_NOT_CONFIG
public static final String SERVER_ID_NOT_CONFIG
- See Also:
- Constant Field Values
-
CLIENT_ID_NOT_CONFIG
public static final String CLIENT_ID_NOT_CONFIG
- See Also:
- Constant Field Values
-
TENANT_ID_NOT_CONFIG
public static final String TENANT_ID_NOT_CONFIG
- See Also:
- Constant Field Values
-
KEY_NOT_CONFIG
public static final String KEY_NOT_CONFIG
- See Also:
- Constant Field Values
-
CERTIFICATE_FILE_NOT_CONFIG
public static final String CERTIFICATE_FILE_NOT_CONFIG
- See Also:
- Constant Field Values
-
CERTIFICATE_FILE_READ_FAIL
public static final String CERTIFICATE_FILE_READ_FAIL
- See Also:
- Constant Field Values
-
AZURE_AUTH_INVALID
public static final String AZURE_AUTH_INVALID
- See Also:
- Constant Field Values
-
AUTH_FILE_NOT_CONFIG
public static final String AUTH_FILE_NOT_CONFIG
- See Also:
- Constant Field Values
-
AUTH_FILE_NOT_EXIST
public static final String AUTH_FILE_NOT_EXIST
- See Also:
- Constant Field Values
-
AUTH_FILE_READ_FAIL
public static final String AUTH_FILE_READ_FAIL
- See Also:
- Constant Field Values
-
AZURE_CLI_AUTH_FAIL
public static final String AZURE_CLI_AUTH_FAIL
- See Also:
- Constant Field Values
-
AZURE_CLI_GET_SUBSCRIPTION_FAIL
public static final String AZURE_CLI_GET_SUBSCRIPTION_FAIL
- See Also:
- Constant Field Values
-
AZURE_CLI_LOAD_TOKEN_FAIL
public static final String AZURE_CLI_LOAD_TOKEN_FAIL
- See Also:
- Constant Field Values
-
AZURE_FOLDER
private static final String AZURE_FOLDER
- See Also:
- Constant Field Values
-
AZURE_PROFILE_NAME
private static final String AZURE_PROFILE_NAME
- See Also:
- Constant Field Values
-
AZURE_TOKEN_NAME
private static final String AZURE_TOKEN_NAME
- See Also:
- Constant Field Values
-
config
protected AuthConfiguration config
-
-
Constructor Detail
-
AzureAuthHelperLegacy
public AzureAuthHelperLegacy(AuthConfiguration config)
Constructor- Parameters:
config-
-
-
Method Detail
-
getAzureClient
public com.microsoft.azure.management.Azure getAzureClient()
-
getLogLevel
protected com.microsoft.rest.LogLevel getLogLevel()
-
azureConfigure
protected com.microsoft.azure.management.Azure.Configurable azureConfigure()
-
getAzureEnvironment
protected com.microsoft.azure.AzureEnvironment getAzureEnvironment(String environment)
-
getAuthObj
protected com.microsoft.azure.management.Azure.Authenticated getAuthObj()
-
getAuthObjFromServerId
protected com.microsoft.azure.management.Azure.Authenticated getAuthObjFromServerId(org.apache.maven.settings.Settings settings, String serverId)Get Authenticated object by referencing server definition in Maven settings.xml- Parameters:
settings- Settings objectserverId- Server Id to search in settings.xml- Returns:
- Authenticated object if configurations are correct; otherwise return null.
-
getAuthObjFromFile
protected com.microsoft.azure.management.Azure.Authenticated getAuthObjFromFile(File authFile)
Get Authenticated object using file.- Parameters:
authFile- Authentication file object.- Returns:
- Authenticated object of file is valid; otherwise return null.
-
getAuthObjFromAzureCli
protected com.microsoft.azure.management.Azure.Authenticated getAuthObjFromAzureCli()
Get Authenticated object using authentication file from Azure CLI 2.0 Note: The integrated Azure CLI in Azure Cloud Shell does not have the accessToken.json, so we need to use MSI to authenticate in the Cloud Shell.- Returns:
- Authenticated object if Azure CLI 2.0 is logged in correctly; otherwise return null.
-
getCredentialFromAzureCliWithServicePrincipal
protected com.microsoft.azure.credentials.ApplicationTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws IOExceptionGet Authenticated object from token file of Azure CLI 2.0 logged with Service Principal Note: This is a workaround for issue https://github.com/microsoft/azure-maven-plugins/issues/125- Returns:
- Authenticated object if Azure CLI 2.0 is logged with Service Principal.
- Throws:
IOException
-
getAppTokenCredentialsFromServer
protected com.microsoft.azure.credentials.ApplicationTokenCredentials getAppTokenCredentialsFromServer(org.apache.maven.settings.Server server)
Get ApplicationTokenCredentials from server definition in Maven settings.xml- Parameters:
server- Server object from settings.xml- Returns:
- ApplicationTokenCredentials object if configuration is correct; otherwise return null.
-
isInCloudShell
public static boolean isInCloudShell()
-
getSubscriptionOfCloudShell
public static String getSubscriptionOfCloudShell() throws IOException
- Throws:
IOException
-
getDefaultSubscriptionObject
private static com.google.gson.JsonObject getDefaultSubscriptionObject() throws IOException- Throws:
IOException
-
getAzureCliTokenList
private static com.google.gson.JsonArray getAzureCliTokenList() throws IOException- Throws:
IOException
-
getServer
private static org.apache.maven.settings.Server getServer(org.apache.maven.settings.Settings settings, String serverId)Get server credential from Maven settings by server Id.- Parameters:
settings- Maven settings object.serverId- Server Id.- Returns:
- Server object if it exists in settings. Otherwise return null.
-
assureServerExist
private static void assureServerExist(org.apache.maven.settings.Server server, String serverId) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptionAssure the server with specified id does exist in settings.xml. It could be the server used for azure authentication. Or, the server used for docker hub authentication of runtime configuration.- Parameters:
server-serverId-- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
getValueFromServerConfiguration
private static String getValueFromServerConfiguration(org.apache.maven.settings.Server server, String key)
Get string value from server configuration section in settings.xml.- Parameters:
server- Server object.key- Key string.- Returns:
- String value if key exists; otherwise, return null.
-
-