Révision c62aae38
Ajouté par Jérôme Schneider il y a plus de 9 ans
mandaye/backends/default.py | ||
---|---|---|
4 | 4 |
from mandaye import config |
5 | 5 |
from mandaye.exceptions import ImproperlyConfigured |
6 | 6 |
|
7 |
class DefaultManagerIDPUser: |
|
8 |
|
|
9 |
@staticmethod |
|
10 |
def get(unique_id, idp_id='default'): |
|
11 |
pass |
|
12 |
|
|
13 |
@staticmethod |
|
14 |
def create(unique_id, idp_id='default'): |
|
15 |
pass |
|
16 |
|
|
17 |
@staticmethod |
|
18 |
def get_or_create(unique_id, idp_id='default'): |
|
19 |
pass |
|
20 |
|
|
21 |
@staticmethod |
|
22 |
def delete(idp_user): |
|
23 |
pass |
|
24 |
|
|
25 |
@staticmethod |
|
26 |
def save(idp_user): |
|
27 |
pass |
|
28 |
|
|
29 |
class DefaultManagerSPUser: |
|
30 |
|
|
31 |
@staticmethod |
|
32 |
def get(login, idp_user, service_provider): |
|
33 |
pass |
|
34 |
|
|
35 |
@staticmethod |
|
36 |
def get_by_id(id): |
|
37 |
pass |
|
7 |
def import_backend(path): |
|
8 |
try: |
|
9 |
mod = import_module(path) |
|
10 |
except ImportError, e: |
|
11 |
raise ImproperlyConfigured('Error importing backend %s: "%s"' % (path, e)) |
|
12 |
return mod |
|
38 | 13 |
|
39 |
@staticmethod |
|
40 |
def get_last_connected(idp_user, service_provider): |
|
41 |
pass |
|
14 |
storage_conn = None |
|
15 |
if config.storage_backend == "mandaye.backends.sql": |
|
16 |
from sqlalchemy import create_engine |
|
17 |
from sqlalchemy.orm import sessionmaker, scoped_session |
|
18 |
if not "sqlite" in config.db_url: |
|
19 |
storage_conn = scoped_session( |
|
20 |
sessionmaker( |
|
21 |
bind=create_engine(config.db_url, pool_size=16, |
|
22 |
pool_recycle=1800) |
|
23 |
) |
|
24 |
) |
|
25 |
else: |
|
26 |
storage_conn = scoped_session( |
|
27 |
sessionmaker( |
|
28 |
bind=create_engine(config.db_url) |
|
29 |
) |
|
30 |
) |
|
42 | 31 |
|
43 |
@staticmethod |
|
44 |
def create(login, post_values, idp_user, service_provider): |
|
45 |
pass |
|
32 |
backend = import_backend(config.storage_backend) |
|
33 |
Association = backend.Association |
|
46 | 34 |
|
47 |
@staticmethod |
|
48 |
def get_or_create(login, post_values, idp_user, service_provider): |
|
49 |
pass |
|
35 |
class AssociationExample(object): |
|
36 |
""" |
|
37 |
association dictionnary return by the following methods: |
|
38 |
{ |
|
39 |
'id': '', # identifier of your association (must be unique) |
|
40 |
'sp_name': '', # name of the service provider (defined in the mappers) |
|
41 |
'sp_login': '', # login on the service provider |
|
42 |
'sp_post_values': '', # the post values for sp login form |
|
43 |
'idp_unique_id:': '', # the unique identifier of the identity provider (ex.: a saml NameID) |
|
44 |
'idp_name': '', # identity provide name |
|
45 |
'last_connection': datetime.datetime, # last connection with this association |
|
46 |
'creation_date': datetime.datetime, # creation date of this association |
|
47 |
} |
|
48 |
""" |
|
50 | 49 |
|
51 | 50 |
@staticmethod |
52 |
def delete(sp_user): |
|
51 |
def get(sp_name, idp_unique_id, idp_name='dafault'): |
|
52 |
""" return a list of dict with associations that matching all of this options """ |
|
53 | 53 |
pass |
54 | 54 |
|
55 | 55 |
@staticmethod |
56 |
def save(sp_user): |
|
56 |
def get_by_id(asso_id): |
|
57 |
""" return an dict of the association with the id or None if it doesn't exist """ |
|
57 | 58 |
pass |
58 | 59 |
|
59 |
class DefaultServiceProvider: |
|
60 |
|
|
61 | 60 |
@staticmethod |
62 |
def get(name): |
|
61 |
def has_id(asso_id): |
|
62 |
""" return a boolean """ |
|
63 | 63 |
pass |
64 | 64 |
|
65 | 65 |
@staticmethod |
66 |
def create(name): |
|
66 |
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name): |
|
67 |
""" update or create an associtaion which match the following values |
|
68 |
return the association id |
|
69 |
""" |
|
67 | 70 |
pass |
68 | 71 |
|
69 | 72 |
@staticmethod |
70 |
def get_or_create(name): |
|
73 |
def delete(asso_id): |
|
74 |
""" delete the association which has the following asso_id """ |
|
71 | 75 |
pass |
72 | 76 |
|
73 | 77 |
@staticmethod |
74 |
def delete(service_provider): |
|
78 |
def get_last_connected(sp_name, idp_unique_id, idp_name='default'): |
|
79 |
""" get the last connecting association which match the parameters |
|
80 |
return a dict of the association |
|
81 |
""" |
|
75 | 82 |
pass |
76 | 83 |
|
77 | 84 |
@staticmethod |
78 |
def save(service_provider): |
|
85 |
def update_last_connection(asso_id): |
|
86 |
""" update the association last conenction time with the current time |
|
87 |
return a dict of the association |
|
88 |
""" |
|
79 | 89 |
pass |
80 |
|
|
81 |
def import_backend(path): |
|
82 |
try: |
|
83 |
mod = import_module(path) |
|
84 |
except ImportError, e: |
|
85 |
raise ImproperlyConfigured('Error importing backend %s: "%s"' % (path, e)) |
|
86 |
return mod |
|
87 |
|
|
88 |
backend = import_backend(config.storage_backend) |
|
89 |
ManagerServiceProvider = backend.ManagerServiceProvider |
|
90 |
ManagerIDPUser = backend.ManagerIDPUser |
|
91 |
ManagerSPUser = backend.ManagerSPUser |
|
92 |
|
Formats disponibles : Unified diff
backends: complete rewrite of the interface
The old interface was to specific for sqlalchemy this new one allow to
write new backends
WARNING: this commit could break compability for some filter which uses
the old interface