Recently I needed to access an Active Directory server via Java and get some info out of it. After poking around, I decided to see if I could use the Apache Directory API to get the job done. I hit some problems pretty quick because some of their docs out of date. The docs are unclear as to how to do the bind and I couldn’t figure out the magic incantation to get it to connect/bind until I did it this way:
1 2 3 4 5 6 7 8 9 10 11 12 | LdapConnection connection = new LdapNetworkConnection(SERVER, PORT); connection.setTimeOut(0); BindRequestImpl request = new BindRequestImpl(); request.setName(USERNAME); request.setCredentials(PASSWORD); BindResponse response = connection.bind(request); if (!connection.isAuthenticated()) { System.out.println("Failed to connect/authenticate"); return; } |