Révision 4c755abe
Ajouté par Jérôme Schneider il y a plus de 9 ans
mandaye/backends/ldap_back.py | ||
---|---|---|
1 | 1 |
|
2 |
import datetime |
|
3 | 2 |
import json |
4 | 3 |
import ldap |
5 | 4 |
import ldap.modlist |
6 | 5 |
import random |
7 | 6 |
|
7 |
from datetime import datetime |
|
8 |
|
|
8 | 9 |
from mandaye import config |
9 | 10 |
from mandaye.log import logger |
10 | 11 |
from mandaye.backends.default import storage_conn |
... | ... | |
33 | 34 |
'sp_post_values': json.loads(ldap_object['spPostValues'][0]), |
34 | 35 |
'idp_unique_id': ldap_object['idpUniqueID'][0], |
35 | 36 |
'idp_name': ldap_object['idpName'][0], |
36 |
'last_connection': datetime.datetime.strptime(
|
|
37 |
'last_connection': datetime.strptime( |
|
37 | 38 |
ldap_object['lastConnectionDate'][0][:14], |
38 | 39 |
'%Y%m%d%H%M%S'), |
39 |
'creation_date': datetime.datetime.strptime(
|
|
40 |
'creation_date': datetime.strptime( |
|
40 | 41 |
ldap_object['creationDate'][0][:14], |
41 | 42 |
'%Y%m%d%H%M%S'), |
42 | 43 |
} |
... | ... | |
73 | 74 |
return False |
74 | 75 |
|
75 | 76 |
@staticmethod |
76 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name='default'): |
|
77 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, |
|
78 |
idp_name='default', creation_date=None, last_connection_date=None): |
|
77 | 79 |
""" update or create an associtaion which match the following values |
78 | 80 |
return the association id |
79 | 81 |
""" |
... | ... | |
81 | 83 |
filterstr='(&(objectClass=MandayeUser)(spName=%s)(spLogin=%s)(idpUniqueID=%s)(idpName=%s))' %\ |
82 | 84 |
(sp_name, sp_login, idp_unique_id, idp_name)) |
83 | 85 |
if not results: |
86 |
creation_date = creation_date or datetime.utcnow() |
|
87 |
last_connection_date = last_connection_date or datetime.utcnow() |
|
84 | 88 |
association = {'spName': str(sp_name), |
85 | 89 |
'spLogin': str(sp_login), |
86 | 90 |
'spPostValues': json.dumps(sp_post_values), |
87 | 91 |
'idpUniqueID': str(idp_unique_id), |
88 | 92 |
'idpName': str(idp_name), |
89 |
'creationDate': datetime.datetime.utcnow().strftime('%Y%m%d%H%M%SZ'),
|
|
90 |
'lastConnectionDate': datetime.datetime.utcnow().strftime('%Y%m%d%H%M%SZ'),
|
|
93 |
'creationDate': creation_date.strftime('%Y%m%d%H%M%SZ'),
|
|
94 |
'lastConnectionDate': last_connection_date.strftime('%Y%m%d%H%M%SZ'),
|
|
91 | 95 |
'objectClass': 'MandayeUser' |
92 | 96 |
} |
93 | 97 |
mod_list = ldap.modlist.addModlist(association) |
... | ... | |
131 | 135 |
""" update the association last connection time with the current time |
132 | 136 |
return a dict of the association |
133 | 137 |
""" |
134 |
last_connection = datetime.datetime.utcnow().strftime("%Y%m%d%H%M%SZ")
|
|
138 |
last_connection = datetime.utcnow().strftime("%Y%m%d%H%M%SZ") |
|
135 | 139 |
dn = "uniqueID=%s,%s" % (asso_id, config.ldap_base_dn) |
136 | 140 |
mod_list = [(ldap.MOD_REPLACE, 'lastConnectionDate', last_connection)] |
137 | 141 |
storage_conn.modify_s(dn, mod_list) |
Formats disponibles : Unified diff
backends: add last_connection_date and creation_date to update_or_create
Closes #5542