31 """manage session data associated to a session identifier""" |
31 """manage session data associated to a session identifier""" |
32 __regid__ = 'sessionmanager' |
32 __regid__ = 'sessionmanager' |
33 |
33 |
34 def __init__(self, vreg): |
34 def __init__(self, vreg): |
35 self.session_time = 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 if self.session_time is not None: |
37 self.cleanup_session_time = vreg.config['cleanup-session-time'] or 43200 |
37 assert self.session_time > 0 |
38 assert self.cleanup_session_time > 0 |
38 self.session_time *= 60 # convert minutes to seconds |
39 self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 120 |
39 self.cleanup_session_time = self.session_time |
|
40 else: |
|
41 self.cleanup_session_time = (vreg.config['cleanup-session-time'] or 1440) * 60 |
|
42 assert self.cleanup_session_time > 0 |
|
43 self.cleanup_anon_session_time = (vreg.config['cleanup-anonymous-session-time'] or 5) * 60 |
40 assert self.cleanup_anon_session_time > 0 |
44 assert self.cleanup_anon_session_time > 0 |
41 if self.session_time: |
|
42 assert self.cleanup_session_time < self.session_time |
|
43 assert self.cleanup_anon_session_time < self.session_time |
|
44 self.authmanager = vreg['components'].select('authmanager', vreg=vreg) |
45 self.authmanager = vreg['components'].select('authmanager', vreg=vreg) |
45 |
46 |
46 def clean_sessions(self): |
47 def clean_sessions(self): |
47 """cleanup sessions which has not been unused since a given amount of |
48 """cleanup sessions which has not been unused since a given amount of |
48 time. Return the number of sessions which have been closed. |
49 time. Return the number of sessions which have been closed. |