server/session.py
changeset 8768 3d105e270abc
parent 8767 a75670ef2d87
child 8769 1672502ac204
equal deleted inserted replaced
8767:a75670ef2d87 8768:3d105e270abc
   187       `HOOKS_DENY_ALL`, this set contains hooks categories that are enabled.
   187       `HOOKS_DENY_ALL`, this set contains hooks categories that are enabled.
   188 
   188 
   189       :attr:`disabled_hook_categories`, when :attr:`hooks_mode` is
   189       :attr:`disabled_hook_categories`, when :attr:`hooks_mode` is
   190       `HOOKS_ALLOW_ALL`, this set contains hooks categories that are disabled.
   190       `HOOKS_ALLOW_ALL`, this set contains hooks categories that are disabled.
   191 
   191 
       
   192     Security level Management:
       
   193 
       
   194       :attr:`read_security` and :attr:`write_security`, boolean flags telling if
       
   195       read/write security is currently activated.
       
   196 
   192     """
   197     """
   193 
   198 
   194     def __init__(self, txid, mode='read'):
   199     def __init__(self, txid, mode='read'):
   195         #: transaction unique id
   200         #: transaction unique id
   196         self.transactionid = txid
   201         self.transactionid = txid
   212         ### hook control attribute
   217         ### hook control attribute
   213         self.hooks_mode = HOOKS_ALLOW_ALL
   218         self.hooks_mode = HOOKS_ALLOW_ALL
   214         self.disabled_hook_cats = set()
   219         self.disabled_hook_cats = set()
   215         self.enabled_hook_cats = set()
   220         self.enabled_hook_cats = set()
   216         self.pruned_hooks_cache = {}
   221         self.pruned_hooks_cache = {}
       
   222 
       
   223 
       
   224         ### security control attributes
       
   225         self.read_security = DEFAULT_SECURITY
       
   226         self.write_security = DEFAULT_SECURITY
   217 
   227 
   218 
   228 
   219     def clear(self):
   229     def clear(self):
   220         """reset internal data"""
   230         """reset internal data"""
   221         self.transaction_data = {}
   231         self.transaction_data = {}
   621     def read_security(self):
   631     def read_security(self):
   622         """return a boolean telling if read security is activated or not"""
   632         """return a boolean telling if read security is activated or not"""
   623         txstore = self._threaddata
   633         txstore = self._threaddata
   624         if txstore is None:
   634         if txstore is None:
   625             return DEFAULT_SECURITY
   635             return DEFAULT_SECURITY
   626         try:
   636         return txstore.read_security
   627             return txstore.read_security
       
   628         except AttributeError:
       
   629             txstore.read_security = DEFAULT_SECURITY
       
   630             return txstore.read_security
       
   631 
   637 
   632     def set_read_security(self, activated):
   638     def set_read_security(self, activated):
   633         """[de]activate read security, returning the previous value set for
   639         """[de]activate read security, returning the previous value set for
   634         later restoration.
   640         later restoration.
   635 
   641 
   637         of this to change security settings.
   643         of this to change security settings.
   638         """
   644         """
   639         txstore = self._threaddata
   645         txstore = self._threaddata
   640         if txstore is None:
   646         if txstore is None:
   641             return DEFAULT_SECURITY
   647             return DEFAULT_SECURITY
   642         oldmode = getattr(txstore, 'read_security', DEFAULT_SECURITY)
   648         oldmode = txstore.read_security
   643         txstore.read_security = activated
   649         txstore.read_security = activated
   644         # dbapi_query used to detect hooks triggered by a 'dbapi' query (eg not
   650         # dbapi_query used to detect hooks triggered by a 'dbapi' query (eg not
   645         # issued on the session). This is tricky since we the execution model of
   651         # issued on the session). This is tricky since we the execution model of
   646         # a (write) user query is:
   652         # a (write) user query is:
   647         #
   653         #
   665     def write_security(self):
   671     def write_security(self):
   666         """return a boolean telling if write security is activated or not"""
   672         """return a boolean telling if write security is activated or not"""
   667         txstore = self._threaddata
   673         txstore = self._threaddata
   668         if txstore is None:
   674         if txstore is None:
   669             return DEFAULT_SECURITY
   675             return DEFAULT_SECURITY
   670         try:
   676         return txstore.write_security
   671             return txstore.write_security
       
   672         except AttributeError:
       
   673             txstore.write_security = DEFAULT_SECURITY
       
   674             return txstore.write_security
       
   675 
   677 
   676     def set_write_security(self, activated):
   678     def set_write_security(self, activated):
   677         """[de]activate write security, returning the previous value set for
   679         """[de]activate write security, returning the previous value set for
   678         later restoration.
   680         later restoration.
   679 
   681 
   681         of this to change security settings.
   683         of this to change security settings.
   682         """
   684         """
   683         txstore = self._threaddata
   685         txstore = self._threaddata
   684         if txstore is None:
   686         if txstore is None:
   685             return DEFAULT_SECURITY
   687             return DEFAULT_SECURITY
   686         oldmode = getattr(txstore, 'write_security', DEFAULT_SECURITY)
   688         oldmode = txstore.write_security
   687         txstore.write_security = activated
   689         txstore.write_security = activated
   688         return oldmode
   690         return oldmode
   689 
   691 
   690     @property
   692     @property
   691     def running_dbapi_query(self):
   693     def running_dbapi_query(self):