diff --git a/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/utils/MavenAuthUtils.java b/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/utils/MavenAuthUtils.java index 49afb1b59a..200e91799a 100644 --- a/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/utils/MavenAuthUtils.java +++ b/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/utils/MavenAuthUtils.java @@ -74,8 +74,16 @@ private static AuthConfiguration convertToAuthConfiguration(MavenAuthConfigurati return authConfiguration; } + /** + * disable unexpected logs from azure identity + */ public static void disableIdentityLogs() { + // add breakpoint on `org.slf4j.Logger.error` to track the logged errors. putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.identity", "off"); + putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.identity.implementation", "off"); + putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.msal4j", "off"); + putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.http.policy", "off"); + putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.implementation", "off"); putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.adal4j", "off"); putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.azure.core.credential", "off"); putPropertyIfNotExist("org.slf4j.simpleLogger.log.com.microsoft.aad.msal4jextensions", "off"); diff --git a/azure-toolkit-libs/azure-toolkit-auth-lib/src/main/java/com/microsoft/azure/toolkit/lib/auth/Account.java b/azure-toolkit-libs/azure-toolkit-auth-lib/src/main/java/com/microsoft/azure/toolkit/lib/auth/Account.java index ff0b340638..4422d13222 100644 --- a/azure-toolkit-libs/azure-toolkit-auth-lib/src/main/java/com/microsoft/azure/toolkit/lib/auth/Account.java +++ b/azure-toolkit-libs/azure-toolkit-auth-lib/src/main/java/com/microsoft/azure/toolkit/lib/auth/Account.java @@ -22,6 +22,7 @@ import com.azure.resourcemanager.resources.models.Tenant; import com.microsoft.azure.toolkit.lib.Azure; import com.microsoft.azure.toolkit.lib.account.IAccount; +import com.microsoft.azure.toolkit.lib.common.bundle.AzureString; import com.microsoft.azure.toolkit.lib.common.cache.CacheEvict; import com.microsoft.azure.toolkit.lib.common.cache.Preloader; import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus; @@ -112,7 +113,9 @@ protected Optional getManagementToken() { final String[] scopes = ScopeUtil.resourceToScopes(this.getEnvironment().getManagementEndpoint()); final TokenRequestContext request = new TokenRequestContext().addScopes(scopes); try { - return this.buildDefaultTokenCredential().getToken(request).blockOptional(); + return this.buildDefaultTokenCredential().getToken(request) + .onErrorResume(Exception.class, t -> Mono.empty()) + .blockOptional(); } catch (Throwable t) { return Optional.empty(); } @@ -168,8 +171,10 @@ private List loadSubscriptions(String tenantId) { final AzureProfile profile = new AzureProfile(tenantId, null, this.getEnvironment()); final ResourceManager.Authenticated client = configureAzure().authenticate(credential, profile); final List subscriptions = client.subscriptions().listAsync().onErrorResume(ex -> { - AzureMessager.getMessager().warning(String.format("Cannot get subscriptions for tenant %s " + - ", please verify you have proper permissions over this tenant, detailed error: %s", tenantId, ex.getMessage())); + AzureMessager.getMessager().warning(AzureString.format( + "Failed to get subscriptions for tenant %s, please confirm you have sufficient permissions." + + " Use %s to explicitly login to a tenant if it requires Multi-Factor Authentication (MFA)." + + " Message: %s", tenantId, "-Dauth.tenant=TENANT_ID", ex.getMessage())); return Flux.fromIterable(new ArrayList<>()); }).map(Subscription::new) .collect(Collectors.toList()).flatMapIterable(s -> s).collectList().block();