[IMP] users_ldap: clean code + add some debug logging
bzr revid: chs@tinyerp.com-20100129161608-awmum09g0bzzn8f1
This commit is contained in:
parent
6b501495db
commit
d5087fd973
|
@ -18,18 +18,12 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv
|
||||
from service import security
|
||||
from osv import fields, osv
|
||||
import pooler
|
||||
import tools
|
||||
from service import security
|
||||
try:
|
||||
import ldap
|
||||
from ldap.filter import filter_format
|
||||
except ImportError:
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("init", netsvc.LOG_WARNING, "could not import ldap!")
|
||||
import ldap
|
||||
from ldap.filter import filter_format
|
||||
|
||||
|
||||
class CompanyLDAP(osv.osv):
|
||||
|
@ -72,6 +66,7 @@ class users(osv.osv):
|
|||
_inherit = "res.users"
|
||||
def login(self, db, login, password):
|
||||
ret = super(users,self).login(db, login, password)
|
||||
tools.debug(ret)
|
||||
if ret:
|
||||
return ret
|
||||
pool = pooler.get_pool(db)
|
||||
|
@ -79,10 +74,11 @@ class users(osv.osv):
|
|||
action_obj = pool.get('ir.actions.actions')
|
||||
cr.execute("""
|
||||
SELECT id, company, ldap_server, ldap_server_port, ldap_binddn, ldap_password,
|
||||
ldap_filter, ldap_base, \"user\", create_user
|
||||
ldap_filter, ldap_base, "user", create_user
|
||||
FROM res_company_ldap
|
||||
WHERE ldap_server != '' and ldap_binddn != '' ORDER BY sequence""")
|
||||
for res_company_ldap in cr.dictfetchall():
|
||||
tools.debug(res_company_ldap)
|
||||
try:
|
||||
l = ldap.open(res_company_ldap['ldap_server'], res_company_ldap['ldap_server_port'])
|
||||
if l.simple_bind_s(res_company_ldap['ldap_binddn'], res_company_ldap['ldap_password']):
|
||||
|
@ -97,11 +93,13 @@ class users(osv.osv):
|
|||
continue
|
||||
if result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
||||
dn = result_data[0][0]
|
||||
tools.debug(dn)
|
||||
name = result_data[0][1]['cn'][0]
|
||||
if l.bind_s(dn, passwd):
|
||||
if l.bind_s(dn, password):
|
||||
l.unbind()
|
||||
cr.execute("SELECT id FROM res_users WHERE login=%s",(tools.ustr(login),))
|
||||
res = cr.fetchone()
|
||||
tools.debug(res)
|
||||
if res:
|
||||
cr.close()
|
||||
return res[0]
|
||||
|
@ -129,6 +127,7 @@ class users(osv.osv):
|
|||
return res
|
||||
l.unbind()
|
||||
except Exception, e:
|
||||
tools.debug(e)
|
||||
continue
|
||||
cr.close()
|
||||
return False
|
||||
|
@ -138,7 +137,6 @@ class users(osv.osv):
|
|||
return super(users,self).check(db, uid, passwd)
|
||||
except: # AccessDenied
|
||||
pass
|
||||
pool = pooler.get_pool(db)
|
||||
cr = pooler.get_db(db).cursor()
|
||||
user = self.browse(cr, 1, uid)
|
||||
if user and user.company_id.ldaps:
|
||||
|
@ -156,7 +154,6 @@ class users(osv.osv):
|
|||
result_type, result_data = l.result(result_id, timeout)
|
||||
if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
||||
dn = result_data[0][0]
|
||||
name = result_data[0][1]['cn']
|
||||
if l.bind_s(dn, passwd):
|
||||
l.unbind()
|
||||
self._uid_cache.setdefault(db, {})[uid] = passwd
|
||||
|
@ -164,6 +161,7 @@ class users(osv.osv):
|
|||
return True
|
||||
l.unbind()
|
||||
except Exception, e:
|
||||
tools.debug(e)
|
||||
pass
|
||||
cr.close()
|
||||
raise security.ExceptionNoTb('AccessDenied')
|
||||
|
|
Loading…
Reference in New Issue