栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 面试经验 > 面试问答

Azure从Azure Java SDK检索VirtualMachines的PublicIPAddress

面试问答 更新时间:发布时间: 百科书网 趣学号

该问题是由使用不正确的身份验证引起的。

下面的身份验证代码仅适用于Azure服务管理。

Configuration config = ManagementConfiguration.configure(          new URI("https://management.core.windows.net),subscriptionId,          keyStoreLocation, // the file path to the JKS          keyStorePassword, // the password for the JKS          KeyStoreType.jks // flags that I'm using a JKS keystore        );

为验证Azure资源管理,文档“验证Azure资源管理请求”(https://msdn.microsoft.com/en-
us/library/azure/dn790557.aspx
)表示“您使用以下命令对资源执行的所有任务必须使用Azure Active
Directory对Azure资源管理器进行身份验证。

因此,您需要使用您的subscription-id,tenant-id,client-id和client-secret修改身份验证配置代码,如下所示:

private static AuthenticationResult getAccessTokenFromServicePrincipalCredentials() throws ServiceUnavailableException, MalformedURLException, ExecutionException, InterruptedException {        AuthenticationContext context;        AuthenticationResult result = null;        ExecutorService service = null;        try { service = Executors.newFixedThreadPool(1); // TODO: add your tenant id context = new AuthenticationContext("https://login.windows.net/" + "<your tenant id>",         false, service); // TODO: add your client id and client secret ClientCredential cred = new ClientCredential("<your client id>",         "<your client secret>"); Future<AuthenticationResult> future = context.acquireToken(         "https://management.azure.com/", cred, null); result = future.get();        } finally { service.shutdown();        }        if (result == null) { throw new ServiceUnavailableException(         "authentication result was null");        }        return result;    }Configuration config = ManagementConfiguration.configure(          null,          new URI("https://management.core.windows.net),"<your-subscription-id>",          getAccessTokenFromServicePrincipalCredentials().getAccessToken()        );

有关适用于Java的ServicePrincipal的完整身份验证代码,请参阅https://github.com/Azure/azure-sdk-
for-java/blob/master/azure-mgmt-samples/src/main/java/com/microsoft/ azure /
samples / authentication /
ServicePrincipalExample.java。

对于线程(使用azure java sdk在Windows
azure中检索订阅的网络列表)的URL,它会移动https://github.com/Azure/azure-sdk-for-java/blob/master/service-
management/ azure-svc-mgmt-network / src / main / java / com / microsoft /
windowsazure / management / network /
NetworkOperations.java。



转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/418618.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号