/** * Performs a user authentication, and returns the proper Distinguished Name * * @param user User name * @param password User password * @return String * @exception DirectoryException */ public String authenticate(String user, String password) throws DirectoryException { try { if (this.conf.getProperty("ldap.manager") != null && this.conf.getProperty("ldap.password") != null) { this.lc.setUser( this.conf.getProperty("ldap.manager"), this.conf.getProperty("ldap.password")); } LDAPDirectoryReader qry = new LDAPDirectoryReader(this.lc, this.conf.getProperty("ldap.basedn")); LDAPDirectoryQuery _q = new LDAPDirectoryQuery(); if (this.conf.getProperty("ldap.auth.userID") == null) { throw new DirectoryException("can't find ldap.auth.userID"); } _q.addCondition(this.conf.getProperty("ldap.auth.userID"), user, LDAPDirectoryQuery.EXACT); List<Identity> _results = qry.search(_q); if (_results == null || _results.size() <= 0) { throw new DirectoryException("user not found"); } Identity _e = (Identity) _results.get(0); if (_e == null) { throw new DirectoryException("user not found"); } this.lc.authenticate(_e.getID(), password, LDAPConnection.AUTHENTICATION_SIMPLE); return _e.getID(); } catch (LDAPException e) { throw new DirectoryException(e.getMessage()); } }