7

I'm using Microsoft aad:adal4j to handle the dynamics crm login from Mobile. After Implementing I am Getting the below Exception.

What am I doing wrong?

Error

java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
at java.util.concurrent.FutureTask.report(FutureTask.java:94)
at java.util.concurrent.FutureTask.get(FutureTask.java:164)
at com.sampleadal.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
at com.microsoft.aad.adal4j.AuthenticationContext.computeSha256Hash(AuthenticationContext.java:798)
at com.microsoft.aad.adal4j.AuthenticationContext.logResult(AuthenticationContext.java:775)
at com.microsoft.aad.adal4j.AuthenticationContext.access$200(AuthenticationContext.java:61)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:130)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:117)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

code

AuthenticationResult result = (AuthenticationResult) new AuthenticationContext(Constants.AUTHORITY_URL, false, Executors.newFixedThreadPool(1)).acquireToken(Constants.SERVICE_URL, Constants.CLIENT_ID, "my_login_id", "my_password", null).get();
Log.d("TAG", "Access Token - " + result.getAccessToken() + "    \n Refresh Token - " + result.getRefreshToken() + "    \n ID Token - " + result.getAccessToken() + "    \n User ID - " + result.getUserInfo().getUniqueId() + "    \n Displayable ID - " + result.getUserInfo().getDispayableId());

Gradle file

compile 'com.microsoft.aad:adal4j:0.0.2'

And also tried this:

Code:

AuthenticationResult result = (AuthenticationResult) new AuthenticationContext(Constants.AUTHORITY_URL, false, Executors.newFixedThreadPool(1)).acquireToken(Constants.SERVICE_URL, new ClientCredential("my_login_id", "my_password"), null).get();

Output

 {
    "error": "unauthorized_client",
    "error_description": "AADSTS70001: Application with identifier 'prasanth' was not found in the directory windows.net\r\nTrace ID: 8c5ccd53-af99-4ff0-8556-501a53080d2f\r\nCorrelation ID: 8651e7f1-a7db-4673-aafb-52fef0d48d2d\r\nTimestamp: 2016-09-26 06:10:41Z"
 }
Prasanth S
  • 3,725
  • 9
  • 43
  • 75

2 Answers2

3

com.microsoft.aad/adal is Azure Active Directory library for Android apps while com.microsoft.azure/adal4j is Azure Active Directory library for Java Web Apps.

http://mvnrepository.com/artifact/com.microsoft.aad/adal/1.0.0 http://mvnrepository.com/artifact/com.microsoft.azure/adal4j

Pandiyan Muthu
  • 1,040
  • 4
  • 21
  • 39
1

@abhishesh already pointed to the right solution. The adald4j library for java was not designed for android and uses a different version of the apache commons library as android does internally. I ran into the same issue using the figo connect API (www.figo.io).

What you need to do:

  1. Download the adald4j Library https://github.com/AzureAD/azure-activedirectory-library-for-java and add it to your project locally.

  2. Download the apache commons library and rename all it's package names (like "org.apache.commons.codec.android"). For example use search and replace across multiple files in sublime text. Add the apache commons library locally as well.

  3. Rename all the package implementations of apache common in your downloaded adald4j library to your new specified name. This makes sure that the library uses your apache commons version and not the android internal version.

Alexander Hoffmann
  • 5,104
  • 3
  • 17
  • 23