29 |
29 |
30 class AbstractSessionManager(component.Component): |
30 class AbstractSessionManager(component.Component): |
31 """manage session data associated to a session identifier""" |
31 """manage session data associated to a session identifier""" |
32 id = 'sessionmanager' |
32 id = 'sessionmanager' |
33 |
33 |
34 def __init__(self): |
34 def __init__(self, vreg): |
35 self.session_time = self.vreg.config['http-session-time'] or None |
35 self.session_time = vreg.config['http-session-time'] or None |
36 assert self.session_time is None or self.session_time > 0 |
36 assert self.session_time is None or self.session_time > 0 |
37 self.cleanup_session_time = self.vreg.config['cleanup-session-time'] or 43200 |
37 self.cleanup_session_time = vreg.config['cleanup-session-time'] or 43200 |
38 assert self.cleanup_session_time > 0 |
38 assert self.cleanup_session_time > 0 |
39 self.cleanup_anon_session_time = self.vreg.config['cleanup-anonymous-session-time'] or 120 |
39 self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 120 |
40 assert self.cleanup_anon_session_time > 0 |
40 assert self.cleanup_anon_session_time > 0 |
41 if self.session_time: |
41 if self.session_time: |
42 assert self.cleanup_session_time < self.session_time |
42 assert self.cleanup_session_time < self.session_time |
43 assert self.cleanup_anon_session_time < self.session_time |
43 assert self.cleanup_anon_session_time < self.session_time |
44 self.authmanager = self.vreg['components'].select('authmanager') |
44 self.authmanager = vreg['components'].select('authmanager', vreg=vreg) |
45 |
45 |
46 def clean_sessions(self): |
46 def clean_sessions(self): |
47 """cleanup sessions which has not been unused since a given amount of |
47 """cleanup sessions which has not been unused since a given amount of |
48 time. Return the number of sessions which have been closed. |
48 time. Return the number of sessions which have been closed. |
49 """ |
49 """ |
90 |
90 |
91 |
91 |
92 class AbstractAuthenticationManager(component.Component): |
92 class AbstractAuthenticationManager(component.Component): |
93 """authenticate user associated to a request and check session validity""" |
93 """authenticate user associated to a request and check session validity""" |
94 id = 'authmanager' |
94 id = 'authmanager' |
|
95 vreg = None # XXX necessary until property for deprecation warning is on appobject |
|
96 |
|
97 def __init__(self, vreg): |
|
98 self.vreg = vreg |
95 |
99 |
96 def authenticate(self, req): |
100 def authenticate(self, req): |
97 """authenticate user and return corresponding user object |
101 """authenticate user and return corresponding user object |
98 |
102 |
99 :raise ExplicitLogin: if authentication is required (no authentication |
103 :raise ExplicitLogin: if authentication is required (no authentication |
111 """ |
115 """ |
112 SESSION_VAR = '__session' |
116 SESSION_VAR = '__session' |
113 |
117 |
114 def __init__(self, appli): |
118 def __init__(self, appli): |
115 self.vreg = appli.vreg |
119 self.vreg = appli.vreg |
116 self.session_manager = self.vreg['components'].select('sessionmanager') |
120 self.session_manager = self.vreg['components'].select('sessionmanager', |
|
121 vreg=self.vreg) |
117 global SESSION_MANAGER |
122 global SESSION_MANAGER |
118 SESSION_MANAGER = self.session_manager |
123 SESSION_MANAGER = self.session_manager |
119 if not 'last_login_time' in self.vreg.schema: |
124 if not 'last_login_time' in self.vreg.schema: |
120 self._update_last_login_time = lambda x: None |
125 self._update_last_login_time = lambda x: None |
121 CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_session_manager) |
126 CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_session_manager) |
122 |
127 |
123 def reset_session_manager(self): |
128 def reset_session_manager(self): |
124 data = self.session_manager.dump_data() |
129 data = self.session_manager.dump_data() |
125 self.session_manager = self.vreg['components'].select('sessionmanager') |
130 self.session_manager = self.vreg['components'].select('sessionmanager', |
|
131 vreg=self.vreg) |
126 self.session_manager.restore_data(data) |
132 self.session_manager.restore_data(data) |
127 global SESSION_MANAGER |
133 global SESSION_MANAGER |
128 SESSION_MANAGER = self.session_manager |
134 SESSION_MANAGER = self.session_manager |
129 |
135 |
130 def clean_sessions(self): |
136 def clean_sessions(self): |
250 self.session_handler = session_handler_fact(self) |
256 self.session_handler = session_handler_fact(self) |
251 self.set_urlresolver() |
257 self.set_urlresolver() |
252 CW_EVENT_MANAGER.bind('after-registry-reload', self.set_urlresolver) |
258 CW_EVENT_MANAGER.bind('after-registry-reload', self.set_urlresolver) |
253 |
259 |
254 def set_urlresolver(self): |
260 def set_urlresolver(self): |
255 self.url_resolver = self.vreg['components'].select('urlpublisher') |
261 self.url_resolver = self.vreg['components'].select('urlpublisher', |
|
262 vreg=self.vreg) |
256 |
263 |
257 def connect(self, req): |
264 def connect(self, req): |
258 """return a connection for a logged user object according to existing |
265 """return a connection for a logged user object according to existing |
259 sessions (i.e. a new connection may be created or an already existing |
266 sessions (i.e. a new connection may be created or an already existing |
260 one may be reused |
267 one may be reused |