def init(self, req, user, auth_type, reuse=False): if reuse: row = self._data.get_row(uid=user.uid()) if row and not self._is_expired(row): self._update_last_access(row) return None row = self._new_session(user.uid(), wiking.generate_random_string(64)) return row['session_id'].export() + ':' + row['session_key'].value()
def _insert(self, req, record, transaction): key = wiking.generate_random_string(256) if not self._call_db_function('cms_crypto_insert_key', record['name'].value(), record['uid'].value(), key, record['new_password'].value(), transaction=transaction): raise pd.DBException(_("New key not created. Maybe it already exists?"))
def _insert(self, req, record, transaction): key = wiking.generate_random_string(256) if not self._call_db_function('cms_crypto_insert_key', record['name'].value(), record['uid'].value(), key, record['new_password'].value(), transaction=transaction): raise pd.DBException( _("New key not created. Maybe it already exists?"))
def report_error(self, req, error): """Invoked for all errors to record their occurance for later review. This method is invoked for every 'ReqestError' exception raised within the application in order to record it and report the problem to the operator/maintainer/developer of the application. All errors are written into server's error log. The amount of information and their format is controlled by the 'log_format' configuration option. Additionally, if the configuration option 'bug_report_address' is set, detailed cgitb traceback of the error is sent to the configured email address. Personal information, such as user's login, IP address or User Agent are intentionally not included in the e-mail but may be logged (if 'log_format' contains them) and paired with the e-mailed traceback using the 'ref_id' value. For 'InternalServerError' a brief traceback (without the details from cgitb) is also written to the error log. This allows jumping right to the code when the error log is observerd in an IDE during development. If 'debug' configuration option is set, the traceback is also logged for other error types for the same purpose. """ if not isinstance(error, wiking.AuthenticationRedirect): info = dict( server_hostname=req.server_hostname(), uri=req.uri(), abs_uri=req.server_uri(current=True) + req.uri(), user=(req.user() and req.user().login() or 'anonymous'), remote_host=req.remote_host(), referer=req.header('Referer'), user_agent=req.header('User-Agent'), method=req.method(), server_software=('Wiking %s, LCG %s, Pytis %s' % (wiking.__version__, lcg.__version__, pytis.__version__)), error_type=error.__class__.__name__, ref_id=wiking.generate_random_string(10), ) log(OPR, wiking.cfg.log_format % info) if isinstance(error, wiking.InternalServerError): log(OPR, error.traceback()) address = wiking.cfg.bug_report_address if address: err = self._send_bug_report(req, error, info, address) if err: log(OPR, "Failed sending error details to %s:" % address, err) else: log(OPR, "Error details sent to %s." % address) elif wiking.cfg.debug: log(OPR, error.traceback())
def session_key(self, length=64): """Generate a new random session key and return it as a string. Arguments: length -- character length of session key string This method may be used to generate a new key to be passed to the 'init()' method, but the caller may decide to generate the key himself. In any case, the security of the authentication method depends on the randomness of the session key, so it should be done with caution. """ return wiking.generate_random_string(length)