1. Download our Official Android App: Forums for Android!

Apps LDAP Integration for Android Apps

Discussion in 'Android Development' started by Kim Luther M Fonte, Aug 25, 2017.

  1. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
  3. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    Hi! Good day! I've already implemented it on my app but it doesn't work on Android Nougat platforms. What do I need to do? Thanks for the reply sir!
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
    When you say it doesn't work, what exactly doesn't work?
     
  5. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    The authentication itself sir. But when I try it on Android Marshmallow and below platforms, it works. I got authenticated. So I assumed that it doesn't support Nougat. :(
     
  6. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
    You don't have to call me sir, I haven't been given a knighthood yet :D
    How are you testing your app? If you are running it on actual device, try connecting it to your computer, and running the app from Android Studio. This will allow you to run it in debug mode and investigate further what could be causing the problem.
     
  7. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    hehehe :D A'right ;) I'm testing it through my smartphone (Nougat, not working) and my friend's smartphone (lollipop, marshmallow, working). Also, I'm testing it in Bluestacks 3 (it's working here). I already connected my phone in my pc and turn it into debug mode but it doesn't prompt me any error.
     
  8. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
    Yeah that's a good start. You need to dig into the code a little more and understand why it's not authenticating. It could be that you're ignoring an exception being thrown. Look for the point at which the code tries to authenticate with the server and set a breakpoint there. Then step through the code and see what happens.
    Without seeing your code it's difficult to offer any more advice.
     
  9. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    The error shown is:

    An error occurred while encoding the LDAP message or sending it to server xxx.xxx.xx.xxx:xxx: NetworkOnMainThreadException(trace='onNetwork(StrictMode.java:1318) / socketWrite(SocketOutputStream.java:111) / write(SocketOutputStream.java:157) / flushBuffer(BufferedOutputStream.java:82) / flush(BufferedOutputStream.java:140) / sendMessage(LDAPConnectionInternals.java:543) / sendMessage(LDAPConnection.java:4255) / process(SImpleBindRequest.java:554) / login(LoginActivity.java:111) / onClick(LoginActivity.java:53) / performClick(View.java:5723) / run(View.java:22689) / handleCallback(Handler.java:836) / dispatchMessage(Handler.java:103) / loop(Looper.java:203) / main(ActivityThread.java:6361) / invoke(Method.java:native) / run(ZygoteInit.java:1063) / main(ZygoteInit.java:924)', ldapSDKVersion=4.0.0, revision=25575
     
  10. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
    Need to see the code for LoginActivity
     
  11. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
    Actually I see your problem. The error is NetworkOnMainThreadException. That means you tried to perform a network operation on the main UI thread, which Android doesn't allow. Normally you would create a separate thread, or AsyncTask to do this.
    And this should be a problem on any device you run the app on.
     
  12. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    Here it is :)

    Code (Text):
    1.  
    2. String uname = _usernameText.getText().toString();
    3. String password = _passwordText.getText().toString();
    4.  
    5. try {
    6.  
    7.             LDAPConnection ldapConnection = new LDAPConnection(URL_AD_SERVER, 389);
    8.             SimpleBindRequest bindRequest = new SimpleBindRequest(uname, password);
    9.             final BindResult bindResult = ldapConnection.bind(bindRequest);
    10.             if(bindResult.getResultCode().isConnectionUsable())
    11.             {
    12.                 loggedIn();
    13.                 final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
    14.                         R.style.AppTheme_Dark_Dialog);
    15.                 progressDialog.setIndeterminate(true);
    16.                 progressDialog.setMessage("Authenticating...");
    17.                 progressDialog.show();
    18.                 new android.os.Handler().postDelayed(
    19.                         new Runnable() {
    20.                             public void run() {
    21.                                 // On complete call either onLoginSuccess
    22.                                 onLoginSuccess();
    23.                                 progressDialog.dismiss();
    24.                             }
    25.                         }, 3000);
    26.             }
    27.         } catch (LDAPException le) {
    28. //            e.printStackTrace();
    29.             String message = le.getMessage();
    30.             if (!message.startsWith("Unable to bind as user ")) {
    31. //                onLoginFailed();
    32.                 Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG).show();
    33.                 _loginButton.setEnabled(true);
    34.             }
    35.  
     
  13. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    I see. How will I start creating a separate thread or AsyncTask for this? :) Sorry, I'm still newbie in mobile development :)
     
  14. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,838
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,838
    11,426
    1,988
    Male
    Software developer
    South West of England
  15. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    Can you please give me an example for that? Thank you very much 😊
     
    sweetndreemy73 likes this.
  16. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    Are there any other APIs or libraries for implementing LDAP authentication for Android apps? Thanks!
     
  17. Kim Luther M Fonte

    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    14
    Joined:
    Aug 25, 2017

    Aug 25, 2017
    14
    2
    26
    Male
    Software Engineer/Developer
    Quezon City, Philippines
    This issue has been solved. Thank you LV426 for the big help! :D
     

Share This Page

Loading...