0001-backends-add-last_connection_date-and-creation_date-.patch
mandaye/backends/default.py | ||
---|---|---|
1 | 1 | |
2 |
from datetime import datetime |
|
2 | 3 |
from importlib import import_module |
3 | 4 | |
4 | 5 |
from mandaye import config |
... | ... | |
68 | 69 |
pass |
69 | 70 | |
70 | 71 |
@staticmethod |
71 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name): |
|
72 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, |
|
73 |
idp_name='default', **kwargs): |
|
72 | 74 |
""" update or create an associtaion which match the following values |
75 |
kwargs: could be last_connection_date or creation_date |
|
73 | 76 |
return the association id |
74 | 77 |
""" |
75 | 78 |
pass |
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', **kwargs): |
|
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 = kwargs.get('creation_date', datetime.utcnow()) |
|
87 |
last_connection_date = kwargs.get('last_connection_date', 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) |
mandaye/backends/sql.py | ||
---|---|---|
71 | 71 |
return False |
72 | 72 | |
73 | 73 |
@staticmethod |
74 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name='default'): |
|
74 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, |
|
75 |
idp_name='default', **kwargs): |
|
75 | 76 |
""" update or create an associtaion which match the following values |
77 |
kwargs: could be last_connection_date or creation_date |
|
76 | 78 |
return the association id |
77 | 79 |
""" |
78 | 80 |
sp_user = storage_conn.query(SPUser).\ |
... | ... | |
105 | 107 |
idp_id=idp_name |
106 | 108 |
) |
107 | 109 |
storage_conn.add(idp_user) |
110 |
creation_date = kwargs.get('creation_date', datetime.utcnow()) |
|
111 |
last_connection_date = kwargs.get('last_connection_date', datetime.utcnow()) |
|
108 | 112 |
sp_user = SPUser( |
109 | 113 |
login=sp_login, |
110 | 114 |
post_values=sp_post_values, |
111 | 115 |
idp_user=idp_user, |
112 |
service_provider=service_provider |
|
116 |
service_provider=service_provider, |
|
117 |
creation_date=creation_date, |
|
118 |
last_connection=last_connection_date |
|
113 | 119 |
) |
114 | 120 |
storage_conn.add(sp_user) |
115 | 121 |
try: |
116 |
- |