azure免费试用帐户无法通过java sdk进行身份验证

时间:2015-10-20 14:34:29

标签: java azure

我使用简单的java sdk代码来验证azure基本连接。我已在天蓝色门户网站的设置中上传了管理证书。但是每当我尝试进行身份验证时,我都会收到以下异常:

  

线程“main”中的异常com.microsoft.windowsazure.exception.ServiceException:ForbiddenError:服务器无法验证请求。验证证书是否有效并与此订阅相关联。       在com.microsoft.windowsazure.exception.ServiceException.createFromXml(ServiceException.java:206)       在com.microsoft.windowsazure.management.LocationOperationsImpl.list(LocationOperationsImpl.java:162)       在com.mycompany.testproj1.test1.main(test1.java:46)

当我尝试使用azure cli

下载证书时
  

$ azure帐户证书导出   info:执行命令帐户证书导出   错误:此订阅不使用管理证书   info:错误信息已记录到/Users/tt/.azure/azure.err   错误:帐户证书导出命令失败

这与我使用免费试用有关吗?

1 个答案:

答案 0 :(得分:1)

这些问题与免费试用无关,请参阅https://azure.microsoft.com/en-us/pricing/free-trial-faq/的第一个常见问题。

enter image description here

有关Azure订阅的限制,请参阅https://azure.microsoft.com/en-us/documentation/articles/azure-subscription-service-limits/

在Azure门户设置中上传管理证书后,您似乎无法使用管理证书成功管理Azure服务。

Java中有部分示例代码用于验证Azure服务管理。

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;
import com.microsoft.windowsazure.management.compute.ComputeManagementService;
import com.microsoft.windowsazure.management.compute.ComputeManagementClient;
import com.microsoft.windowsazure.management.network.NetworkManagementService;
import com.microsoft.windowsazure.management.network.NetworkManagementClient;

String uri = "https://management.core.windows.net/";
        String subscriptionId = "<your subscription id>";
        String keyStoreLocation = "<KeyStore.jks>";
        String keyStorePassword = "<password for KeyStore>";

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

// For Compute Management
ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);

//For Networing Management
NetworkManagementClient client = NetworkManagementService.create(config);

// Others like above

代码依赖于下面pom.xml中的一些maven存储库,你需要在项目中添加什么。

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-svc-mgmt</artifactId>
    <version>0.8.3</version>
</dependency>
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-svc-mgmt-compute</artifactId>
    <version>0.8.3</version>
</dependency>
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-svc-mgmt-network</artifactId>
    <version>0.8.3</version>
</dependency>

对于Azure CLI的错误,我认为您错过了一些必要的步骤,如下所示。

首先,使用命令login和Azure用户名&amp;用于连接Azure订阅的密码。

$ azure login -u <username@hostname>

其次,切换Azure服务管理模式以获取导出证书。

$ azure config mode asm

最后,下载certiticate。

$ azure account cert export

然后,您可以在当前路径中找到名为<subscription-id>.pem的证书文件。

有关详情,请参阅https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-connect/

对此主题有任何疑虑,请随时告诉我。

相关问题