• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps LDAP Integration for Android Apps

Hello everyone! Has anyone here do know some APIs or libraries packages for LDAP integration for Android app? I will be using it for AD authentication for the app. Thanks and cheers! :)
 
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!
 
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. :(
 
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.
 
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.
 
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.
 
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
 
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.
 
Here it is :)

Code:
String uname = _usernameText.getText().toString();
String password = _passwordText.getText().toString();

try {

            LDAPConnection ldapConnection = new LDAPConnection(URL_AD_SERVER, 389);
            SimpleBindRequest bindRequest = new SimpleBindRequest(uname, password);
            final BindResult bindResult = ldapConnection.bind(bindRequest);
            if(bindResult.getResultCode().isConnectionUsable())
            {
                loggedIn();
                final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
                        R.style.AppTheme_Dark_Dialog);
                progressDialog.setIndeterminate(true);
                progressDialog.setMessage("Authenticating...");
                progressDialog.show();
                new android.os.Handler().postDelayed(
                        new Runnable() {
                            public void run() {
                                // On complete call either onLoginSuccess
                                onLoginSuccess();
                                progressDialog.dismiss();
                            }
                        }, 3000);
            }
        } catch (LDAPException le) {
//            e.printStackTrace();
            String message = le.getMessage();
            if (!message.startsWith("Unable to bind as user ")) {
//                onLoginFailed();
                Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG).show();
                _loginButton.setEnabled(true);
            }
 
Back
Top Bottom