0
votes

I am using simple java sdk code to verify the azure basic connection. I have uploaded the management certificate in the settings in the azure portal. But I am getting the following exception whenever I try to authenticate :

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)

When i try to download the certificate using azure 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

Is this related to my use of free trial ?

1
Could you paste Java code for this thread at here? And what steps you follow when using azure cli to download the certificate?Peter Pan

1 Answers

1
votes

The issues are not related to free trial, refer to the first faq of https://azure.microsoft.com/en-us/pricing/free-trial-faq/.

enter image description here

For the limits of Azure Subscription, please refer to https://azure.microsoft.com/en-us/documentation/articles/azure-subscription-service-limits/.

Seems that you can’t use management certificate to manage Azure Services successfully after uploaded management certificate in the settings of Azure Portal.

There is the partial sample code in Java for authenticating Azure Service Management.

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

The code dependents on some maven repositories below in the pom.xml what you need to add in your project.

<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>

For the error of Azure CLI, I think you missed some necessary steps as below.

Firstly, using command login and Azure username & password to connect your Azure subscription.

$ azure login -u <username@hostname>

Secondly, switching the Azure Service Management Mode for export certificate.

$ azure config mode asm

Lastly, downloading certiticate.

$ azure account cert export

Then, you can find the cert file called <subscription-id>.pem at the current path.

For details, you can refer to https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-connect/.

Any concern for this thread, please feel free to let me know.