def __after__(self): db.session.close() response.pragma = None if not app_globals.cache_enabled or 'flash' in session._session(): return if c._cache_disabled: return del response.cache_control.no_cache if len(session._session().keys()) == 2 and \ not len(request.cookies.keys()): session._current_obj().__dict__['_sess'] = None response.cache_control.public = True else: response.cache_control.private = True # Set vary header (this will set Cookie as a value for the vary header # so different content can be served to logged in users set_vary_header() response.cache_control.must_revalidate = c._must_revalidate if not c._must_revalidate: response.cache_control.max_age = 3600 * 6
def UserHasRoles(session_key, roles=[] ): hasRoles = False try: s = session._current_obj() hasRoles = all([role in s[session_key]["user"]["roles"] for role in roles]) except: pass return hasRoles
def wrapper(fn, self, *args, **kwargs): if _service_doc: sdoc = _service_doc() try: if "oauth" not in sdoc["service_auth"]["service_authz"]: return fn(self, *args, **kwargs) except: raise ValueError("Missing service_document for checking if OAUTH access is enabled.") if _pre_cond: precond = cont = _pre_cond() else: precond = cont = True if precond: success = { "status": status.Unknown, "user": None, "parameters": None } try: success["parameters"], success["user"] = _authobj.check_request(r._current_obj(), _mapper) if success["parameters"] is None: success["status"] = status.NoSignature else: success["status"] = status.Okay except BadOAuthSignature as e: success["status"] = status.BadSignature success["detail"] = e.message cont = False except: success["status"] = status.Error success["detail"] = repr(sys.exc_info()) log.exception("Caught Exception in authorize") cont = False sess = session._current_obj() sess[_session_key] = success # log.error("in wrap:"+repr(sess[_session_key])) if cont and _roles: cont = UserHasRoles(_session_key, _roles) if _post_cond: cont = _post_cond(cont) if cont: try: return fn(self, *args, **kwargs) finally: pass else: h = {"WWW-Authenticate": "OAuth realm=\"{0}\"".format(_realm)} log.error("Authorization Required") res.headers.update(h) abort(401, "OAuth Authorization Required", headers=h)
def wrapper(fn, self, *args, **kwargs): if _service_doc: sdoc = _service_doc() try: if "basicauth" not in sdoc["service_auth"]["service_authz"]: return fn(self, *args, **kwargs) except: raise ValueError( "Missing service_document for checking if OAUTH access is enabled." ) if _pre_cond: precond = _pre_cond() else: precond = True # if precondition is true, continue with auth. otherwise skip if precond: sess = session._current_obj() success = {} success["user"], success["status"] = _authUtil.validate_session( _roles) sess[_session_key] = success # log.error("in wrap:"+repr(sess[_session_key])) cont = success["status"] and success["user"] if cont: success["status"] = status.Okay else: success["status"] = status.NotAuthorized if _post_cond: cont = _post_cond(cont) else: cont = True if cont: return fn(self, *args, **kwargs) else: h = {"WWW-Authenticate": "Basic realm=\"{0}\"".format(_realm)} log.error("Authorization Required") response.headers.update(h) abort(401, "Basic Authorization Required", headers=h)
def wrapper(fn, self, *args, **kwargs): if _service_doc: sdoc = _service_doc() try: if "basicauth" not in sdoc["service_auth"]["service_authz"]: return fn(self, *args, **kwargs) except: raise ValueError("Missing service_document for checking if OAUTH access is enabled.") if _pre_cond: precond = _pre_cond() else: precond = True # if precondition is true, continue with auth. otherwise skip if precond: sess = session._current_obj() success = {} success["user"], success["status"] = _authUtil.validate_session(_roles) sess[_session_key] = success # log.error("in wrap:"+repr(sess[_session_key])) cont = success["status"] and success["user"] if cont: success["status"] = status.Okay else: success["status"] = status.NotAuthorized if _post_cond: cont = _post_cond(cont) else: cont = True if cont: return fn(self, *args, **kwargs) else: h = {"WWW-Authenticate": "Basic realm=\"{0}\"".format(_realm)} log.error("Authorization Required") response.headers.update(h) abort(401, "Basic Authorization Required", headers=h)
def __after__(self): db.session.close() response.pragma = None if not app_globals.cache_enabled or 'flash' in session._session(): return if c._cache_disabled: return del response.cache_control.no_cache if len(session._session().keys()) == 2 and not len(request.cookies.keys()): session._current_obj().__dict__['_sess'] = None response.cache_control.public = True else: response.cache_control.private = True response.cache_control.must_revalidate = c._must_revalidate if not c._must_revalidate: response.cache_control.max_age = 3600 * 6 response.expires = datetime.utcnow() + \ timedelta(seconds=response.cache_control.max_age)
def __after__(self): db.session.close() response.pragma = None if not app_globals.cache_enabled or 'flash' in session._session(): return if c._cache_disabled: return del response.cache_control.no_cache if len(session._session().keys()) == 2 and not len( request.cookies.keys()): session._current_obj().__dict__['_sess'] = None response.cache_control.public = True else: response.cache_control.private = True response.cache_control.must_revalidate = c._must_revalidate if not c._must_revalidate: response.cache_control.max_age = 3600 * 6 response.expires = datetime.utcnow() + \ timedelta(seconds=response.cache_control.max_age)
pool.task_done() else: destination = self.export_path log.debug("Special Exporting "+svnroot+" to "+destination+" for "+self.username) self.export(svnroot, self.username, self.password, destination) log.debug("SVN export thread exiting") #end helper functions/classes roster = get_roster(svnroot, username, password,unique_id) export_total = float(len(roster)) for student in roster: pool.put(student) tempdir = mkdtemp() update_session('import_status', "SVN import: initializing threads and starting export",unique_id) if not special: for i in range(threadcount): ExportThread(svnroot, subdir, username, password, tempdir,revision, session._current_obj(), special, unique_id).start() pool.join() else: rmtree(tempdir) thread = ExportThread(svnroot, "", username, password, tempdir, revision, session._current_obj(), special, unique_id) thread.start() thread.join() update_session('import_status', "Export of "+svnroot+" with subdirectory "+subdir+" to "+tempdir+" for "+username+" complete",unique_id) return tempdir def try_svn_login(username, password, url): try_svn_login.attempts = 0 def ssl_server_trust_prompt( trust_dict ): return True, 1000, False