tags:

views:

478

answers:

3

I am currently using the netscape.ldap package to handle LDAP Connection and Authentication. I don't know if this is the best framework for LDAP Management but it's what I've got anyways.

Using this I really have to check if the user exists or not by doing so obisouly ugly and bad statements, such as followed:

 try{
        conn.connect(this.host, this.port, this.dn, this.password);
        this.validUser = true;
    }
    catch(LDAPException e) {
        this.validUser = false;
    }

This is seriously very ugly and bad practice, however, it's simple and understandable. And that's the most important part, I want it to be as simple and easy on the eyes as possible.

However the documentation for netscape.ldap feels outdated. So, anyone got suggestions on how I can implement this better or with another package? ( Prefferable not with hundreds of dependencies ).

Also I'd like to be able to do something like: conn.add("user", "pass"); without having to bother looking into the various security methods I'd have to implement to get the password right.

+1  A: 

Have a look at the Spring support for LDAP operations. You can find an introduction on the SpringSource website. I'm not sure if it suits your requirements (it has dependencies after all) but it works well.

yawn
That's not "simple" or easy looking on the eyes. I want something that is as straight forward as netscape.ldap or just use netscape.ldap. And NOT have something that has so many dependencies as Spring does.
Filip Ekberg
I am not sure what you mean with "easy looking on the eyes". Have a look at the example in the introduction - the API is very simple and straightforward to work with. The dependency on Spring however (as I wrote in my answer btw., so there is no need for a downvote, really) might exclude this particular solution for you. Note that you do *not* need to use Spring as container in order to work with Spring LDAP.
yawn
Down-voting means that the Answer did not contribute anything usefull to the actual question / problem. Which yours did not. Therefore you were down-voted. I already know about spring and it is not as easy to use as netscape.ldap and it has a lot of dependencies that I disslike. So, your answer did not contribute anything to the question, I'm sorry.
Filip Ekberg
+1  A: 

I think a better approach is always to search the ldap structure. In that sense you would create a connection (perhaps an anonymous bind) and then do a search. Something like this:

LDAPConnection ld = new LDAPConnection();
ld.connect(LDAP_SERVER, LDAP_PORT);
LDAPSearchResults res = ld.search(BASE_DN, SEARCH_SCOPE, "(uid=" + THE_ID +")", null, false);

Check the result. If you get anything (a DN) then there is something.

rmarimon
This won't really work, you won't know if the user password and username is correct? The BASE_DN contains that or?
Filip Ekberg
+1  A: 

Hi, I was at LDAPCon/LinuxCon from September 21 to 23. There were some very nice presentations made. There was this one titled "UnboundID LDAP SDK". The whole concept was that JNDI is a generic directory API not really an LDAP API. Also, Netstcape directory SDK hasn't been updated since 2002 and JLDAP is obsolete. So, there are no good LDAP-specific SDK available for Java developers.

The presentation was given by two former Sun software engineers (Neil Wilson and David Ivy) who started their own company (UnboundID) and wrote the entire SDK specifically for LDAP and put it under GPL v2 and GPL v2.1 (developer's choice) license. I have attached their presentation here. Hopefully you'll like it.

UnboundID LDAP API Presentation

Nikolas Sakic