本文整理汇总了Python中MaKaC.accessControl.AccessWrapper.setIP方法的典型用法代码示例。如果您正苦于以下问题:Python AccessWrapper.setIP方法的具体用法?Python AccessWrapper.setIP怎么用?Python AccessWrapper.setIP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaKaC.accessControl.AccessWrapper
的用法示例。
在下文中一共展示了AccessWrapper.setIP方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildAW
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
def buildAW(ak, onlyPublic=False):
aw = AccessWrapper()
aw.setIP(str(request.remote_addr))
if ak and not onlyPublic:
# If we have an authenticated request, require HTTPS
# Dirty hack: Google calendar converts HTTP API requests from https to http
# Therefore, not working with Indico setup (requiring https for HTTP API authenticated)
if not request.is_secure and api_settings.get('require_https') and request.user_agent.browser != 'google':
raise HTTPAPIError('HTTPS is required', 403)
aw.setUser(ak.user.as_avatar)
return aw
示例2: buildAW
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
def buildAW(ak, req, onlyPublic=False):
aw = AccessWrapper()
aw.setIP(str(req.get_remote_ip()))
if ak and not onlyPublic:
# If we have an authenticated request, require HTTPS
minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
# Dirty hack: Google calendar converts HTTP API requests from https to http
# Therefore, not working with Indico setup (requiring https for HTTP API authenticated)
if not request.is_secure and minfo.isAPIHTTPSRequired() and request.user_agent.browser != 'google':
raise HTTPAPIError('HTTPS is required', 403)
aw.setUser(ak.getUser())
return aw
示例3: RH
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
#.........这里部分代码省略.........
#redirect to https if necessary
if self._checkHttpsRedirect():
return
DBMgr.getInstance().startRequest()
self._startRequestSpecific2RH() # I.e. implemented by Room Booking request handlers
textLog.append("%s : Database request started"%(datetime.now() - self._startTime))
Logger.get('requestHandler').info('[pid=%s] Request %s started (%s)' % (os.getpid(),id(self._req), self._req.unparsed_uri))
# notify components that the request has started
self._notify('requestStarted', self._req)
forcedConflicts = Config.getInstance().getForceConflicts()
try:
while retry>0:
if retry < MAX_RETRIES:
# notify components that the request is being retried
self._notify('requestRetry', self._req, MAX_RETRIES - retry)
try:
Logger.get('requestHandler').info('\t[pid=%s] from host %s' % (os.getpid(), self.getHostIP()))
try:
# clear the fossile cache at the start of each request
fossilize.clearCache()
# delete all queued emails
GenericMailer.flushQueue(False)
DBMgr.getInstance().sync()
# keep a link to the web session in the access wrapper
# this is used for checking access/modification key existence
# in the user session
self._aw.setIP( self.getHostIP() )
self._aw.setSession(self._getSession())
#raise(str(dir(self._websession)))
self._setSessionUser()
self._setLang(params)
if self._getAuth():
if self._getUser():
Logger.get('requestHandler').info('Request %s identified with user %s (%s)' % (id(self._req), self._getUser().getFullName(), self._getUser().getId()))
if not self._tohttps and Config.getInstance().getAuthenticatedEnforceSecure():
self._tohttps = True
if self._checkHttpsRedirect():
return
#if self._getUser() != None and self._getUser().getId() == "893":
# profile = True
self._reqParams = copy.copy( params )
self._checkParams( self._reqParams )
self._checkProtection()
security.Sanitization.sanitizationCheck(self._target,
self._reqParams,
self._aw, self._doNotSanitizeFields)
if self._doProcess:
if profile:
import profile, pstats
proffilename = os.path.join(Config.getInstance().getTempDir(), "stone%s.prof" % str(random.random()))
result = [None]
profile.runctx("result[0] = self._process()", globals(), locals(), proffilename)
res = result[0]
else:
res = self._process()
# Save web session, just when needed
示例4: RH
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
#.........这里部分代码省略.........
return errors.WPLaTeXError(self, e).display()
@jsonify_error
def _processRestrictedHTML(self, e):
return errors.WPRestrictedHTML(self, escape(str(e))).display()
@jsonify_error
def _processHtmlScriptError(self, e):
""" TODO """
return errors.WPHtmlScriptError(self, escape(str(e))).display()
@jsonify_error
def _processHtmlForbiddenTag(self, e):
""" TODO """
return errors.WPRestrictedHTML(self, escape(str(e))).display()
def _process_retry_setup(self):
# clear the fossile cache at the start of each request
fossilize.clearCache()
# clear after-commit queue
flush_after_commit_queue(False)
# delete all queued emails
GenericMailer.flushQueue(False)
# clear the existing redis pipeline
if self._redisPipeline:
self._redisPipeline.reset()
def _process_retry_auth_check(self, params):
# keep a link to the web session in the access wrapper
# this is used for checking access/modification key existence
# in the user session
self._aw.setIP(request.remote_addr)
self._setSessionUser()
if self._getAuth():
if self._getUser():
Logger.get('requestHandler').info('Request %s identified with user %s (%s)' % (
request, self._getUser().getFullName(), self._getUser().getId()))
if not self._tohttps and Config.getInstance().getAuthenticatedEnforceSecure():
self._tohttps = True
if self._checkHttpsRedirect():
return self._responseUtil.make_redirect()
self._checkCSRF()
self._reqParams = copy.copy(params)
def _process_retry_do(self, profile):
profile_name, res = '', ''
try:
# old code gets parameters from call
# new code utilizes of flask.request
if len(inspect.getargspec(self._checkParams).args) < 2:
cp_result = self._checkParams()
else:
cp_result = self._checkParams(self._reqParams)
if isinstance(cp_result, (current_app.response_class, Response)):
return '', cp_result
func = getattr(self, '_checkParams_' + request.method, None)
if func:
cp_result = func()
if isinstance(cp_result, (current_app.response_class, Response)):
return '', cp_result
示例5: ServiceBase
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
class ServiceBase(RequestHandlerBase):
"""
The ServiceBase class is the basic class for services.
"""
def __init__(self, params, session, req):
"""
Constructor. Initializes provate variables
@param req: HTTP Request provided by the previous layer
"""
RequestHandlerBase.__init__(self, req)
self._reqParams = self._params = params
self._requestStarted = False
self._websession = session
# Fill in the aw instance with the current information
self._aw = AccessWrapper()
self._aw.setIP(self.getHostIP())
self._aw.setSession(session)
self._aw.setUser(session.getUser())
self._target = None
self._startTime = None
self._tohttps = self._req.is_https()
self._endTime = None
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods
self._tempFilesToDelete = []
# Methods =============================================================
def _getSession( self ):
"""
Returns the web session associated to the received mod_python
request.
"""
return self._websession
def _checkParams(self):
"""
Checks the request parameters (normally overloaded)
"""
pass
def _checkProtection( self ):
"""
Checks protection when accessing resources (normally overloaded)
"""
pass
def _processError(self):
"""
Treats errors occured during the process of a RH, returning an error string.
@param e: the exception
@type e: An Exception-derived type
"""
trace = traceback.format_exception(*sys.exc_info())
return ''.join(trace)
def _deleteTempFiles( self ):
if len(self._tempFilesToDelete) > 0:
for file in self._tempFilesToDelete:
os.remove(file)
def process(self):
"""
Processes the request, analyzing the parameters, and feeding them to the
_getAnswer() method (implemented by derived classes)
"""
ContextManager.set('currentRH', self)
self._setLang()
self._checkParams()
self._checkProtection()
try:
security.Sanitization.sanitizationCheck(self._target,
self._params,
self._aw)
except (HtmlScriptError, HtmlForbiddenTag), e:
raise HTMLSecurityError('ERR-X0','HTML Security problem. %s ' % str(e))
if self._doProcess:
if Config.getInstance().getProfile():
import profile, pstats, random
proffilename = os.path.join(Config.getInstance().getTempDir(), "service%s.prof" % random.random())
result = [None]
profile.runctx("result[0] = self._getAnswer()", globals(), locals(), proffilename)
answer = result[0]
rep = Config.getInstance().getTempDir()
stats = pstats.Stats(proffilename)
stats.strip_dirs()
stats.sort_stats('cumulative', 'time', 'calls')
stats.dump_stats(os.path.join(rep, "IndicoServiceRequestProfile.log"))
os.remove(proffilename)
else:
answer = self._getAnswer()
self._deleteTempFiles()
#.........这里部分代码省略.........
示例6: ServiceBase
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
class ServiceBase(RequestHandlerBase):
"""
The ServiceBase class is the basic class for services.
"""
UNICODE_PARAMS = False
def __init__(self, params):
RequestHandlerBase.__init__(self)
if not self.UNICODE_PARAMS:
params = unicode_struct_to_utf8(params)
self._reqParams = self._params = params
self._requestStarted = False
# Fill in the aw instance with the current information
self._aw = AccessWrapper()
self._aw.setIP(request.remote_addr)
self._aw.setUser(session.user)
self._target = None
self._startTime = None
self._tohttps = request.is_secure
self._endTime = None
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods
self._tempFilesToDelete = []
self._redisPipeline = None
# Methods =============================================================
def _checkParams(self):
"""
Checks the request parameters (normally overloaded)
"""
pass
def _checkProtection( self ):
"""
Checks protection when accessing resources (normally overloaded)
"""
pass
def _processError(self):
"""
Treats errors occured during the process of a RH, returning an error string.
@param e: the exception
@type e: An Exception-derived type
"""
trace = traceback.format_exception(*sys.exc_info())
return ''.join(trace)
def _deleteTempFiles( self ):
if len(self._tempFilesToDelete) > 0:
for file in self._tempFilesToDelete:
os.remove(file)
def process(self):
"""
Processes the request, analyzing the parameters, and feeding them to the
_getAnswer() method (implemented by derived classes)
"""
ContextManager.set('currentRH', self)
self._setLang()
self._checkParams()
self._checkProtection()
try:
security.Sanitization.sanitizationCheck(self._target, self._params, self._aw)
except HtmlForbiddenTag as e:
raise HTMLSecurityError('ERR-X0','HTML Security problem. %s ' % str(e))
if self._doProcess:
if Config.getInstance().getProfile():
import profile, pstats, random
proffilename = os.path.join(Config.getInstance().getTempDir(), "service%s.prof" % random.random())
result = [None]
profile.runctx("result[0] = self._getAnswer()", globals(), locals(), proffilename)
answer = result[0]
rep = Config.getInstance().getTempDir()
stats = pstats.Stats(proffilename)
stats.strip_dirs()
stats.sort_stats('cumulative', 'time', 'calls')
stats.dump_stats(os.path.join(rep, "IndicoServiceRequestProfile.log"))
os.remove(proffilename)
else:
answer = self._getAnswer()
self._deleteTempFiles()
return answer
def _getAnswer(self):
"""
To be overloaded. It should contain the code that does the actual
business logic and returns a result (python JSON-serializable object).
If this method is not overloaded, an exception will occur.
If you don't want to return an answer, you should still implement this method with 'pass'.
"""
#.........这里部分代码省略.........
示例7: RH
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
#.........这里部分代码省略.........
DBMgr.getInstance().startRequest()
self._startRequestSpecific2RH() # I.e. implemented by Room Booking request handlers
textLog.append("%s : Database request started" % (datetime.now() - self._startTime))
Logger.get('requestHandler').info('[pid=%s] Request %s started' % (
os.getpid(), request))
# notify components that the request has started
self._notify('requestStarted')
forcedConflicts = Config.getInstance().getForceConflicts()
try:
while retry>0:
if retry < MAX_RETRIES:
# notify components that the request is being retried
self._notify('requestRetry', MAX_RETRIES - retry)
try:
Logger.get('requestHandler').info('\t[pid=%s] from host %s' % (os.getpid(), request.remote_addr))
try:
# clear the fossile cache at the start of each request
fossilize.clearCache()
# delete all queued emails
GenericMailer.flushQueue(False)
# clear the existing redis pipeline
if self._redisPipeline:
self._redisPipeline.reset()
DBMgr.getInstance().sync()
# keep a link to the web session in the access wrapper
# this is used for checking access/modification key existence
# in the user session
self._aw.setIP(request.remote_addr)
self._setSessionUser()
self._setLang(params)
if self._getAuth():
if self._getUser():
Logger.get('requestHandler').info('Request %s identified with user %s (%s)' % (
request, self._getUser().getFullName(), self._getUser().getId()))
if not self._tohttps and Config.getInstance().getAuthenticatedEnforceSecure():
self._tohttps = True
if self._checkHttpsRedirect():
return self._responseUtil.make_redirect()
self._checkCSRF()
self._reqParams = copy.copy(params)
self._checkParams(self._reqParams)
func = getattr(self, '_checkParams_' + request.method, None)
if func:
func()
self._checkProtection()
func = getattr(self, '_checkProtection_' + request.method, None)
if func:
func()
security.Sanitization.sanitizationCheck(self._target,
self._reqParams,
self._aw, self._doNotSanitizeFields)
if self._doProcess:
if profile:
import profile, pstats
proffilename = os.path.join(Config.getInstance().getTempDir(), "stone%s.prof" % str(random.random()))
result = [None]
profile.runctx("result[0] = self._process()", globals(), locals(), proffilename)
示例8: ServiceBase
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setIP [as 别名]
class ServiceBase(RequestHandlerBase):
"""
The ServiceBase class is the basic class for services.
"""
def __init__(self, params, remoteHost, session):
"""
Constructor. Initializes provate variables
@param req: HTTP Request provided by the previous layer
"""
self._params = params
self._requestStarted = False
self._websession = session
# Fill in the aw instance with the current information
self._aw = AccessWrapper()
self._aw.setIP(remoteHost)
self._aw.setSession(session)
self._aw.setUser(session.getUser())
self._target = None
self._startTime = None
self._endTime = None
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods
self._tempFilesToDelete = []
# Methods =============================================================
def _getSession( self ):
"""
Returns the web session associated to the received mod_python
request.
"""
return self._websession
def _checkParams(self):
"""
Checks the request parameters (normally overloaded)
"""
pass
def _checkProtection( self ):
"""
Checks protection when accessing resources (normally overloaded)
"""
pass
def _processError(self):
"""
Treats errors occured during the process of a RH, returning an error string.
@param e: the exception
@type e: An Exception-derived type
"""
trace = traceback.format_exception(*sys.exc_info())
return ''.join(trace)
def _sendEmails( self ):
if hasattr( self, "_emailsToBeSent" ):
for email in self._emailsToBeSent:
GenericMailer.send(GenericNotification(email))
def _deleteTempFiles( self ):
if len(self._tempFilesToDelete) > 0:
for file in self._tempFilesToDelete:
os.remove(file)
def process(self):
"""
Processes the request, analyzing the parameters, and feeding them to the
_getAnswer() method (implemented by derived classes)
"""
self._setLang()
self._checkParams()
self._checkProtection()
try:
security.sanitizationCheck(self._target,
self._params,
self._aw)
except (htmlScriptError, htmlForbiddenTag), e:
raise HTMLSecurityError('ERR-X0','HTML Security problem - you might be using forbidden tags: %s ' % str(e))
if self._doProcess:
answer = self._getAnswer()
self._sendEmails()
self._deleteTempFiles()
return answer