• 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

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.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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);
            }
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones