backends: add has_sp_login method to test if a local login is already used
Refs #6000
This commit is contained in:
parent
1a868080ad
commit
8b1775a3ad
|
@ -95,3 +95,9 @@ class AssociationExample(object):
|
|||
return a dict of the association
|
||||
"""
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def has_sp_login(sp_login, sp_name):
|
||||
""" Test if a service provider login is present on the databases
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -145,3 +145,11 @@ class Association(object):
|
|||
mod_list = [(ldap.MOD_REPLACE, 'lastConnectionDate', last_connection)]
|
||||
storage_conn.modify_s(dn, mod_list)
|
||||
|
||||
@staticmethod
|
||||
def has_sp_login(sp_login, sp_name):
|
||||
results = storage_conn.search_s(config.ldap_base_dn, ldap.SCOPE_ONELEVEL,
|
||||
filterstr='(&(objectClass=MandayeUser)(spName=%s)(spLogin=%s))' %\
|
||||
(sp_name, sp_login))
|
||||
if results:
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -172,3 +172,15 @@ class Association(object):
|
|||
sp_user.last_connection = datetime.utcnow()
|
||||
storage_conn.add(sp_user)
|
||||
|
||||
@staticmethod
|
||||
def has_sp_login(sp_login, sp_name):
|
||||
sp_user = storage_conn.query(SPUser).\
|
||||
join(ServiceProvider).\
|
||||
filter(ServiceProvider.name==sp_name).\
|
||||
filter(SPUser.login==sp_login).\
|
||||
count()
|
||||
if sp_user:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
|
Reference in New Issue