Search in sources :

Example 1 with ServicePrincipalAccount

use of com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount in project azure-maven-plugins by microsoft.

the class AzureAccount method loginAsync.

public Mono<Account> loginAsync(@Nonnull AuthConfiguration auth, boolean enablePersistence) {
    Objects.requireNonNull(auth, "Auth configuration is required for login.");
    Objects.requireNonNull(auth.getType(), "Auth type is required for login.");
    Preconditions.checkArgument(auth.getType() != AuthType.AUTO, "Auth type 'auto' is illegal for login.");
    if (auth.getEnvironment() != null) {
        Azure.az(AzureCloud.class).set(auth.getEnvironment());
    }
    AuthType type = auth.getType();
    final Account targetAccount;
    if (auth.getType() == AuthType.SERVICE_PRINCIPAL) {
        targetAccount = new ServicePrincipalAccount(auth);
    } else {
        Map<AuthType, Supplier<Account>> accountByType = buildAccountMap();
        if (!accountByType.containsKey(type)) {
            return Mono.error(new LoginFailureException(String.format("Unsupported auth type '%s', supported values are: %s.", type, accountByType.keySet().stream().map(Object::toString).map(StringUtils::lowerCase).collect(Collectors.joining(", ")))));
        }
        targetAccount = accountByType.get(type).get();
    }
    return loginAsync(targetAccount, enablePersistence);
}
Also used : IAzureAccount(com.microsoft.azure.toolkit.lib.account.IAzureAccount) AzureCliAccount(com.microsoft.azure.toolkit.lib.auth.core.azurecli.AzureCliAccount) ServicePrincipalAccount(com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount) OAuthAccount(com.microsoft.azure.toolkit.lib.auth.core.oauth.OAuthAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) LoginFailureException(com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) ServicePrincipalAccount(com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount)

Aggregations

IAzureAccount (com.microsoft.azure.toolkit.lib.account.IAzureAccount)1 AzureCliAccount (com.microsoft.azure.toolkit.lib.auth.core.azurecli.AzureCliAccount)1 DeviceCodeAccount (com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount)1 OAuthAccount (com.microsoft.azure.toolkit.lib.auth.core.oauth.OAuthAccount)1 ServicePrincipalAccount (com.microsoft.azure.toolkit.lib.auth.core.serviceprincipal.ServicePrincipalAccount)1 LoginFailureException (com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException)1 AuthType (com.microsoft.azure.toolkit.lib.auth.model.AuthType)1 Supplier (java.util.function.Supplier)1 StringUtils (org.apache.commons.lang3.StringUtils)1