USERS_LDAP: fix when module not installed
bzr revid: ced-4293a339237c7b8fa33f8000e79b1f1651fc1f57
This commit is contained in:
parent
34add232ae
commit
cb3ecb3b1a
|
@ -53,41 +53,43 @@ res_company()
|
||||||
def ldap_login(oldfnc):
|
def ldap_login(oldfnc):
|
||||||
def _ldap_login(db, login, passwd):
|
def _ldap_login(db, login, passwd):
|
||||||
cr = pooler.get_db(db).cursor()
|
cr = pooler.get_db(db).cursor()
|
||||||
cr.execute("select id, name, ldap_server, ldap_binddn, ldap_password, ldap_filter, ldap_base from res_company where ldap_server != '' and ldap_binddn != ''")
|
module_obj = pooler.get_pool(cr.dbname).get('ir.module.module')
|
||||||
for res_company in cr.dictfetchall():
|
module_ids = module_obj.search(cr, 1, [('name', '=', 'users_ldap')])
|
||||||
try:
|
if module_ids:
|
||||||
l = ldap.open(res_company['ldap_server'])
|
state = module_obj.read(cr, 1, module_ids, ['state'])[0]['state']
|
||||||
if l.simple_bind_s(res_company['ldap_binddn'], res_company['ldap_password']):
|
if state in ('installed', 'to upgrade', 'to remove'):
|
||||||
base = res_company['ldap_base']
|
cr.execute("select id, name, ldap_server, ldap_binddn, ldap_password, ldap_filter, ldap_base from res_company where ldap_server != '' and ldap_binddn != ''")
|
||||||
scope = ldap.SCOPE_SUBTREE
|
for res_company in cr.dictfetchall():
|
||||||
filter = res_company['ldap_filter']%(login,)
|
try:
|
||||||
retrieve_attributes = None
|
l = ldap.open(res_company['ldap_server'])
|
||||||
result_id = l.search(base, scope, filter, retrieve_attributes)
|
if l.simple_bind_s(res_company['ldap_binddn'], res_company['ldap_password']):
|
||||||
timeout = 60
|
base = res_company['ldap_base']
|
||||||
result_type, result_data = l.result(result_id, timeout)
|
scope = ldap.SCOPE_SUBTREE
|
||||||
if not result_data:
|
filter = res_company['ldap_filter']%(login,)
|
||||||
|
retrieve_attributes = None
|
||||||
|
result_id = l.search(base, scope, filter, retrieve_attributes)
|
||||||
|
timeout = 60
|
||||||
|
result_type, result_data = l.result(result_id, timeout)
|
||||||
|
if not result_data:
|
||||||
|
continue
|
||||||
|
if 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):
|
||||||
|
cr.execute("select id from res_users where login=%s",(login.encode('utf-8'),))
|
||||||
|
res = cr.fetchone()
|
||||||
|
if res:
|
||||||
|
cr.close()
|
||||||
|
return res[0]
|
||||||
|
users_obj = pooler.get_pool(cr.dbname).get('res.users')
|
||||||
|
action_obj = pooler.get_pool(cr.dbname).get('ir.actions.actions')
|
||||||
|
action_id = action_obj.search(cr, 1, [('usage', '=', 'menu')])[0]
|
||||||
|
res = users_obj.create(cr, 1, {'name': name, 'login': login.encode('utf-8'), 'company_id': res_company['id'], 'action_id': action_id})
|
||||||
|
cr.commit()
|
||||||
|
cr.close()
|
||||||
|
return res
|
||||||
|
except Exception, e:
|
||||||
continue
|
continue
|
||||||
if 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):
|
|
||||||
cr.execute("select id from res_users where login=%s",(login.encode('utf-8'),))
|
|
||||||
res = cr.fetchone()
|
|
||||||
if res:
|
|
||||||
cr.close()
|
|
||||||
return res[0]
|
|
||||||
users_obj = pooler.get_pool(cr.dbname).get('res.users')
|
|
||||||
action_obj = pooler.get_pool(cr.dbname).get('ir.actions.actions')
|
|
||||||
action_id = action_obj.search(cr, 1, [('usage', '=', 'menu')])[0]
|
|
||||||
res = users_obj.create(cr, 1, {'name': name, 'login': login.encode('utf-8'), 'company_id': res_company['id'], 'action_id': action_id})
|
|
||||||
cr.commit()
|
|
||||||
cr.close()
|
|
||||||
return res
|
|
||||||
else:
|
|
||||||
print "failed"
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
continue
|
|
||||||
cr.close()
|
cr.close()
|
||||||
return oldfnc(db, login, passwd)
|
return oldfnc(db, login, passwd)
|
||||||
return _ldap_login
|
return _ldap_login
|
||||||
|
@ -99,29 +101,34 @@ def ldap_check(oldfnc):
|
||||||
if security._uid_cache.has_key(uid) and (security._uid_cache[uid]==passwd):
|
if security._uid_cache.has_key(uid) and (security._uid_cache[uid]==passwd):
|
||||||
return True
|
return True
|
||||||
cr = pooler.get_db(db).cursor()
|
cr = pooler.get_db(db).cursor()
|
||||||
users_obj = pooler.get_pool(cr.dbname).get('res.users')
|
module_obj = pooler.get_pool(cr.dbname).get('ir.module.module')
|
||||||
user = users_obj.browse(cr, 1, uid)
|
module_ids = module_obj.search(cr, 1, [('name', '=', 'users_ldap')])
|
||||||
if user and user.company_id.ldap_server and user.company_id.ldap_binddn:
|
if module_ids:
|
||||||
company = user.company_id
|
state = module_obj.read(cr, 1, module_ids, ['state'])[0]['state']
|
||||||
try:
|
if state in ('installed', 'to upgrade', 'to remove'):
|
||||||
l = ldap.open(company.ldap_server)
|
users_obj = pooler.get_pool(cr.dbname).get('res.users')
|
||||||
if l.simple_bind_s(company.ldap_binddn, company.ldap_password):
|
user = users_obj.browse(cr, 1, uid)
|
||||||
base = company['ldap_base']
|
if user and user.company_id.ldap_server and user.company_id.ldap_binddn:
|
||||||
scope = ldap.SCOPE_SUBTREE
|
company = user.company_id
|
||||||
filter = company['ldap_filter']%(user.login,)
|
try:
|
||||||
retrieve_attributes = None
|
l = ldap.open(company.ldap_server)
|
||||||
result_id = l.search(base, scope, filter, retrieve_attributes)
|
if l.simple_bind_s(company.ldap_binddn, company.ldap_password):
|
||||||
timeout = 60
|
base = company['ldap_base']
|
||||||
result_type, result_data = l.result(result_id, timeout)
|
scope = ldap.SCOPE_SUBTREE
|
||||||
if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
filter = company['ldap_filter']%(user.login,)
|
||||||
dn=result_data[0][0]
|
retrieve_attributes = None
|
||||||
name=result_data[0][1]['cn']
|
result_id = l.search(base, scope, filter, retrieve_attributes)
|
||||||
if l.bind_s(dn, passwd):
|
timeout = 60
|
||||||
security._uid_cache[uid] = passwd
|
result_type, result_data = l.result(result_id, timeout)
|
||||||
cr.close()
|
if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
||||||
return True
|
dn=result_data[0][0]
|
||||||
except Exception, e:
|
name=result_data[0][1]['cn']
|
||||||
print e
|
if l.bind_s(dn, passwd):
|
||||||
|
security._uid_cache[uid] = passwd
|
||||||
|
cr.close()
|
||||||
|
return True
|
||||||
|
except Exception, e:
|
||||||
|
pass
|
||||||
cr.close()
|
cr.close()
|
||||||
return oldfnc(db, uid, passwd)
|
return oldfnc(db, uid, passwd)
|
||||||
return _ldap_check
|
return _ldap_check
|
||||||
|
|
Loading…
Reference in New Issue