Android Microsoft Dynamics CRM adal4j登录问题

时间:2016-09-23 11:20:45

标签: java android dynamics-crm adal4j

我使用Microsoft aad:adal4j来处理来自Mobile的动态crm登录。实施后我得到以下例外。

我做错了什么?

错误

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)

代码

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

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

还尝试了这个:

代码:

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();

输出

 {
    "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"
 }

2 个答案:

答案 0 :(得分:2)

com.microsoft.aad / adal是适用于Android应用的Azure Active Directory库,而com.microsoft.azure/adal4j是适用于Java Web Apps的Azure Active Directory库。

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

答案 1 :(得分:1)

@abhishesh已经指出了正确的解决方案。 java的adald4j库不是为android而设计的,并且使用了不同版本的apache commons库,就像android在内部一样。 我使用figo connect API(www.figo.io)遇到了同样的问题。

您需要做什么:

  1. 下载adald4j资料库https://github.com/AzureAD/azure-activedirectory-library-for-java 并在本地将其添加到您的项目中。

  2. 下载apache commons库并重命名所有包名(如“org.apache.commons.codec.android”)。例如,在sublime文本中使用搜索和替换多个文件。 也可以在本地添加apache commons库。

  3. 将下载的adald4j库中常见的apache的所有包实现重命名为新的指定名称。这可以确保库使用您的apache commons版本而不是android内部版本。