azure-ad-msalazure-keyvaultazure-data-explorerkusto-java-sdk

No such method for createFromSecret()


I am using msal4j library on version 0.6.0-preview and java 8 in the repo.

            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>msal4j</artifactId>
                <version>0.6.0-preview</version>
            </dependency>

This msal4j library is to set up Azure keyvault as well as kusto data ingestion.

Here's my code:

ConnectionStringBuilder csb = ConnectionStringBuilder.createWithAadApplicationCredentials(clusterPath, appId, appKey, authorityId);
Client kustoClient = ClientFactory.createClient(csb);

createClient() failed because in TokenProviderFactory.java, it is expecting createFromSecret() but ClientCredentialFactory.java does not have createFromSecret() but create(). Thus it is throwing me an error:

 com.microsoft.aad.msal4j.ClientCredentialFactory.createFromSecret(Ljava/lang/String;)
    Lcom/microsoft/aad/msal4j/IClientSecret;
| java.lang.NoSuchMethodError: com.microsoft.aad.msal4j.ClientCredentialFactory.createFromSecret(Ljava/lang/String;)
    Lcom/microsoft/aad/msal4j/IClientSecret;
                    at com.microsoft.azure.kusto.data.auth.TokenProviderFactory.createTokenProvider(TokenProviderFactory.java:25)
                    at com.microsoft.azure.kusto.data.ClientImpl.<init>(ClientImpl.java:52)
                    at com.microsoft.azure.kusto.data.ClientFactory.createClient(ClientFactory.java:16)

Here's the limitations we face:

  1. We are not able to upgrade java 11 in our repo due to other dependencies so we are stuck with java 8.
  2. We are not able to upgrade the msal4j library to higher version due to other dependencies.

But regardless of that, why is the TokenProviderFactory.java has the following code;

clientSecret clientSecret = ClientCredentialFactory.createFromSecret(csb.getApplicationKey());

But ClientCredentialFactory.java does not have createFromSecret()? What can we do as a workaround?


Solution

  • One way to solve this issue would be to do the authentication yourselves and create the client with a token provider

     ConnectionStringBuilder.createWithAadTokenProviderAuthentication(null, () -> getToken())
    

    The best solution would be to use versions that suite most dependencies. Use maven helper intellij plugin to find this out.

    Other options to avoid any collision is to shadow the Kusto library and its dependencies.

    As for the question - the reason why createFromSecret doesnt seem to be in ClientCredentialFactory is that the method does not exist on your version but does exist in the version Kusto SDK is using.