1
|
|
2
|
from importlib import import_module
|
3
|
|
4
|
from mandaye import config
|
5
|
from mandaye.exceptions import ImproperlyConfigured
|
6
|
|
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
|
13
|
|
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
|
)
|
31
|
elif config.storage_backend == "mandaye.backends.ldap_back":
|
32
|
import ldap
|
33
|
storage_conn = ldap.initialize(config.ldap_url)
|
34
|
storage_conn.protocol_version = ldap.VERSION3
|
35
|
storage_conn.simple_bind(config.ldap_bind_dn, config.ldap_bind_password)
|
36
|
|
37
|
backend = import_backend(config.storage_backend)
|
38
|
Association = backend.Association
|
39
|
|
40
|
class AssociationExample(object):
|
41
|
"""
|
42
|
association dictionnary return by the following methods:
|
43
|
{
|
44
|
'id': '', # identifier of your association (must be unique)
|
45
|
'sp_name': '', # name of the service provider (defined in the mappers)
|
46
|
'sp_login': '', # login on the service provider
|
47
|
'sp_post_values': '', # the post values for sp login form
|
48
|
'idp_unique_id:': '', # the unique identifier of the identity provider (ex.: a saml NameID)
|
49
|
'idp_name': '', # identity provide name
|
50
|
'last_connection': datetime.datetime, # last connection with this association
|
51
|
'creation_date': datetime.datetime, # creation date of this association
|
52
|
}
|
53
|
"""
|
54
|
|
55
|
@staticmethod
|
56
|
def get(sp_name, idp_unique_id, idp_name='default'):
|
57
|
""" return a list of dict with associations that matching all of this options """
|
58
|
pass
|
59
|
|
60
|
@staticmethod
|
61
|
def get_by_id(asso_id):
|
62
|
""" return an dict of the association with the id or None if it doesn't exist """
|
63
|
pass
|
64
|
|
65
|
@staticmethod
|
66
|
def has_id(asso_id):
|
67
|
""" return a boolean """
|
68
|
pass
|
69
|
|
70
|
@staticmethod
|
71
|
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name):
|
72
|
""" update or create an associtaion which match the following values
|
73
|
return the association id
|
74
|
"""
|
75
|
pass
|
76
|
|
77
|
@staticmethod
|
78
|
def delete(asso_id):
|
79
|
""" delete the association which has the following asso_id """
|
80
|
pass
|
81
|
|
82
|
@staticmethod
|
83
|
def get_last_connected(sp_name, idp_unique_id, idp_name='default'):
|
84
|
""" get the last connecting association which match the parameters
|
85
|
return a dict of the association
|
86
|
"""
|
87
|
pass
|
88
|
|
89
|
@staticmethod
|
90
|
def update_last_connection(asso_id):
|
91
|
""" update the association last conenction time with the current time
|
92
|
return a dict of the association
|
93
|
"""
|
94
|
pass
|