我在调用Azure.getCurrentSubscription()时遇到以下异常:很少我们会遇到“异常1”,而在大多数情况下,我们会遇到“异常2”。
环境: 使用Azure Java SDK:azure-1.5.0版
我们创建了AD应用程序和服务主体,并使用以下ID(例如,Subscription ID,Tenant ID,Client ID和Application Key)连接到Azure.getCurrentSubscription()
注意:我们尚未使用证书配置App密钥,仅配置了简单的客户机密。
代码示例:
delivered
例外1 。
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(infoProps.getProperty("ClientID"), infoProps.getProperty("TenantID"), infoProps.getProperty("AppKey"), AzureEnvironment.AZURE);
Azure azureObj =
Azure.authenticate(credentials).withSubscription(infoProps.getProperty("SubscriptionID"));
azureObj.getCurrentSubscription();
例外2 。
ERROR **com.microsoft.aad.adal4j.AuthenticationContext** - [Correlation ID: c7b9459f-1e11-4ded-889a-3bb1dd096855] **Request to acquire token failed**.
com.microsoft.aad.adal4j.AuthenticationException: {}
at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:107)
at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:818)
at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:66)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:174)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:163)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.RuntimeException: java.io.IOException: com.microsoft.aad.adal4j.AuthenticationException: {}
at rx.exceptions.Exceptions.propagate(Exceptions.java:57)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463)
at rx.observables.BlockingObservable.last(BlockingObservable.java:226)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.SupportsGettingByIdImpl.getById(SupportsGettingByIdImpl.java:22)
at com.microsoft.azure.management.Azure.getCurrentSubscription(Azure.java:416)