python 3.4 - ldap3 operation: SEARCH seems to fail (search_filter syntax vs RFC4515) -


edit: tl;dr - search_filter argument used in search might non conforming rfc4515.

i've got django server running version 1.8.4 on ubuntu 14.04. i'm using python 3.4 , i'm trying configure ldap authentication using ldap3.

this part of upgrade versions named above 1.6.2, 12.04, , 2.7.3, respectively. working correctly, assume problem on end , not authentication server.

the way works i've got file called authenticate_user.py receives username , password passed through html form shown below.

def authenticatestudent(request):     username = request.post.get('username','')     logger.info("user " + username + " has logged in.")     password = request.post.get('password','')     x = auth(username, password)     retval = x.authenticatepy()     logger.info('retvale '+str(retval)) #this returns false     #more code , more logging 

the method instantiates object auth class (shown below), stores username , password within, , calls authenticatepy() method in class.

import logging import sys import os.path,subprocess import ldap3 ldap ldap3 import connection, server, simple, sync, subtree,   logger = logging.getlogger('submission')  class auth():      studentname = ""     studentemail = ""     studentmatrik = ""      def __init__(self, username, password):         self.username = username         self.password = password      def authenticatepy(self):         user_dn = "cn="+self.username+",ou=users,ou=data,ou=prod,ou=authserver,dc=domain,dc=tld"         base_dn = "dc=domain,dc=tld"         server = server("authserver.domain.tld", port=636, use_ssl=true)          filter = "uid="+self.username #might incorrect         try:             #if authentication successful, full user data             connect = connection(server, user=user_dn, password=self.password)             connect.bind()             logger.info('connection bind complete!') #the last logged message method             result = connect.search(search_base=base_dn, search_filter=filter, search_scope=subtree)             logger.info('searching complete') #does not appear in log             # return user data results             connect.unbind()             uname = result[0][1]['cn'][0]             studentname = result[0][1]['fullname'][0]             studentemail = result[0][1]['imhauptemail'][0]             studentmatrik = result[0][1]['immatrikelnr'][0]             logger.info('studentname '+str(studentname))             if uname == self.username :                 return studentname + '$' + studentemail + '$' + studentmatrik             else:                 return false         except ldap.ldapexceptionerror:             connect.unbind()             return false 

the last log message i'm seeing 'connection bind complete!' , i'm not sure what's breaking. idea i'm doing wrong?

edit: i've been troubleshooting while , i'm beginning think problem in search_filter argument i'm passing search function. ldap3 documentation on search operation states filter string should rfc4515 compliant, , i'm not sure i'm providing that.

i'm author of ldap3. ldap filter must included in parenthesis. please try adding leading , traling parenthesis filter:

filter = "(uid="+self.username + ")"

bye, giovanni


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -