2015-10-20 123 views
0

我正在使用简单的java sdk代码来验证azure基本连接。我已经在Azure门户的设置中上传了管理证书。但我收到以下异常,每当我尝试验证:azure免费试用帐户无法通过java认证sdk

Exception in thread "main" com.microsoft.windowsazure.exception.ServiceException: ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription. at com.microsoft.windowsazure.exception.ServiceException.createFromXml(ServiceException.java:206) at com.microsoft.windowsazure.management.LocationOperationsImpl.list(LocationOperationsImpl.java:162) at com.mycompany.testproj1.test1.main(test1.java:46)

当我尝试下载使用蔚蓝CLI

$ azure account cert export info: Executing command account cert export error: This subscription does not use a management certificate info: Error information has been recorded to /Users/tt/.azure/azure.err error: account cert export command failed

证书这是有关我的使用免费试用?

+0

您可以在此粘贴此代码的Java代码吗?当使用azure cli下载证书时,您遵循哪些步骤? –

回答

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 

代码依赖于下面的一些maven仓库在pom.xml中需要添加到项目中。

<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用户名&密码连接您的Azure订阅。

$ azure login -u <[email protected]> 

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

$ azure config mode asm 

最后,下载certiticate。

$ azure account cert export 

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

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

任何关于此主题,请随时让我知道。

+0

感谢它工作正常。 – Squid