2

I am using 1.0.0-beta4.1 Azure Java SDK. This is my code for authentication

    // TODO Auto-generated method stub
    String client = "xxxxxxxxxxx";
    String tenant = "xxxxxxxxxxx";
    String key = "xxxxxxxxxxx";
    String subscriptionId = "xxxxxxxxxxx";

    ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client, tenant, key, AzureEnvironment.AZURE);
    Azure azure = Azure.authenticate(credentials).withSubscription(subscriptionId);
    System.out.println("Listing all resource groups");

The code doesn't throw any error in case of incorrect credentials. Is there any way to find whether the authentication was successful or not.

user1142317
  • 533
  • 1
  • 8
  • 20
  • The current hack I am applying is to check the class variables of "azure" object is null or not and based on that deduce whether the authentication was successful or not. – user1142317 Jan 20 '17 at 15:32

2 Answers2

2

According to your code, it seems that missing some required methods which include configure(), please see below.

Azure azure = Azure.configure()  // Initial an Azure.Configurable object
                   .withLogLevel(HttpLoggingInterceptor.Level.BASIC)
                   .authenticate(credentials)
                   .withSubscription(subscriptionId);

Please try to use the code above instead of yours. Any update, please feel free to let me know.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks. That worked. Now it throws an exception in case of incorrect credentials. – user1142317 Jan 24 '17 at 15:11
  • What is the Jar version you are using to run this application. Am unable to use withLogLevel(HttpLoggingInterceptor.Level.BASIC), getting the following compile time error :The method withLogLevel(LogLevel) in the type AzureConfigurable is not applicable for the arguments (HttpLoggingInterceptor.Level) – Esh Oct 25 '17 at 12:57
0

I just got the same exception and I was able to resolve it by replacing HttpLoggingInterceptor.Level.BASIC with LogLevel.BASIC.

Aso, I would like to inform that I used the dependency

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0</version>