--- C:\Documents and Settings\William\My Documents\plugins.py-orig +++ C:\Documents and Settings\William\My Documents\plugins.py-search @@ -25,6 +25,7 @@ from zope.interface import implements import ldap +from ldap import filter from repoze.who.interfaces import IAuthenticator, IMetadataProvider @@ -76,7 +77,7 @@ try: dn = self._get_dn(environ, identity) password = identity['password'] - except (KeyError, TypeError, ValueError): + except (KeyError, TypeError, ValueError, IndexError): return None if not hasattr(self.ldap_connection, 'simple_bind_s'): @@ -111,10 +112,24 @@ @raise ValueError: If the C{login} key is not in the I{identity} dict. """ - try: - return u'uid=%s,%s' % (identity['login'], self.base_dn) - except (KeyError, TypeError): - raise ValueError + #try: + # return u'uid=%s,%s' % (identity['login'], self.base_dn) + #except (KeyError, TypeError): + # raise ValueError + self.ldap_connection.simple_bind() + if '@' in identity['login']: + filters = filter.filter_format('(mail=%s)', (identity['login'],)) + else: + filters = filter.filter_format('(uid=%s)', (identity['login'],)) + environ['repoze.who.logger'].info('LDAP looking for: %s.' % filters) + results = self.ldap_connection.search_s( + self.base_dn, + ldap.SCOPE_SUBTREE, + filters, + ('dn',) + ) + #self.ldap_connection.unbind() + return results[0][0] def __repr__(self): return '<%s %s>' % (self.__class__.__name__, id(self))