web/application.py
changeset 9032 629a8d49d6f5
parent 9031 6ff29f2879da
child 9040 3c85e734ce00
equal deleted inserted replaced
9031:6ff29f2879da 9032:629a8d49d6f5
    59 
    59 
    60 class AbstractSessionManager(component.Component):
    60 class AbstractSessionManager(component.Component):
    61     """manage session data associated to a session identifier"""
    61     """manage session data associated to a session identifier"""
    62     __regid__ = 'sessionmanager'
    62     __regid__ = 'sessionmanager'
    63 
    63 
    64     def __init__(self, vreg):
    64     def __init__(self, repo):
       
    65         vreg = repo.vreg
    65         self.session_time = vreg.config['http-session-time'] or None
    66         self.session_time = vreg.config['http-session-time'] or None
    66         self.authmanager = vreg['components'].select('authmanager', vreg=vreg)
    67         self.authmanager = vreg['components'].select('authmanager', repo=repo)
    67         interval = (self.session_time or 0) / 2.
    68         interval = (self.session_time or 0) / 2.
    68         if vreg.config.anonymous_user() is not None:
    69         if vreg.config.anonymous_user() is not None:
    69             self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 5 * 60
    70             self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 5 * 60
    70             assert self.cleanup_anon_session_time > 0
    71             assert self.cleanup_anon_session_time > 0
    71             if self.session_time is not None:
    72             if self.session_time is not None:
   127 
   128 
   128 class AbstractAuthenticationManager(component.Component):
   129 class AbstractAuthenticationManager(component.Component):
   129     """authenticate user associated to a request and check session validity"""
   130     """authenticate user associated to a request and check session validity"""
   130     __regid__ = 'authmanager'
   131     __regid__ = 'authmanager'
   131 
   132 
   132     def __init__(self, vreg):
   133     def __init__(self, repo):
   133         self.vreg = vreg
   134         self.vreg = repo.vreg
   134 
   135 
   135     def validate_session(self, req, session):
   136     def validate_session(self, req, session):
   136         """check session validity, reconnecting it to the repository if the
   137         """check session validity, reconnecting it to the repository if the
   137         associated connection expired in the repository side (hence the
   138         associated connection expired in the repository side (hence the
   138         necessity for this method).
   139         necessity for this method).
   156 
   157 
   157 class CookieSessionHandler(object):
   158 class CookieSessionHandler(object):
   158     """a session handler using a cookie to store the session identifier"""
   159     """a session handler using a cookie to store the session identifier"""
   159 
   160 
   160     def __init__(self, appli):
   161     def __init__(self, appli):
       
   162         self.repo = appli.repo
   161         self.vreg = appli.vreg
   163         self.vreg = appli.vreg
   162         self.session_manager = self.vreg['components'].select('sessionmanager',
   164         self.session_manager = self.vreg['components'].select('sessionmanager',
   163                                                               vreg=self.vreg)
   165                                                               repo=self.repo)
   164         global SESSION_MANAGER
   166         global SESSION_MANAGER
   165         SESSION_MANAGER = self.session_manager
   167         SESSION_MANAGER = self.session_manager
   166         if self.vreg.config.mode != 'test':
   168         if self.vreg.config.mode != 'test':
   167             # don't try to reset session manager during test, this leads to
   169             # don't try to reset session manager during test, this leads to
   168             # weird failures when running multiple tests
   170             # weird failures when running multiple tests
   170                                   self.reset_session_manager)
   172                                   self.reset_session_manager)
   171 
   173 
   172     def reset_session_manager(self):
   174     def reset_session_manager(self):
   173         data = self.session_manager.dump_data()
   175         data = self.session_manager.dump_data()
   174         self.session_manager = self.vreg['components'].select('sessionmanager',
   176         self.session_manager = self.vreg['components'].select('sessionmanager',
   175                                                               vreg=self.vreg)
   177                                                               repo=self.repo)
   176         self.session_manager.restore_data(data)
   178         self.session_manager.restore_data(data)
   177         global SESSION_MANAGER
   179         global SESSION_MANAGER
   178         SESSION_MANAGER = self.session_manager
   180         SESSION_MANAGER = self.session_manager
   179 
   181 
   180     @property
   182     @property