本文整理汇总了Python中privacyidea.lib.policy.PolicyClass.get_client_policy方法的典型用法代码示例。如果您正苦于以下问题:Python PolicyClass.get_client_policy方法的具体用法?Python PolicyClass.get_client_policy怎么用?Python PolicyClass.get_client_policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类privacyidea.lib.policy.PolicyClass
的用法示例。
在下文中一共展示了PolicyClass.get_client_policy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SystemController
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import get_client_policy [as 别名]
#.........这里部分代码省略.........
try:
param = getLowerParams(request.params)
user = getParam(param, "user", required)
realm = getParam(param, "realm", required)
scope = getParam(param, "scope", required)
action = getParam(param, "action", required)
client = getParam(param, "client", required)
pol = {}
if scope in ["admin", "system", "license"]:
pol = self.Policy.getPolicy({"scope":scope})
if len(pol) > 0:
# Policy active for this scope!
pol = self.Policy.getPolicy({"user":user,
"realm":realm,
"scope":scope,
"action":action,
"client":client})
res["allowed"] = len(pol) > 0
res["policy"] = pol
if len(pol) > 0:
c.audit['info'] = "allowed by policy %s" % pol.keys()
else:
# No policy active for this scope
c.audit['info'] = "allowed since no policies in scope %s" % scope
res["allowed"] = True
res["policy"] = "No policies in scope %s" % scope
else:
log.debug("checking policy for client %s, scope %s, action %s, realm %s and user %s" %
(client, scope, action, realm, user))
pol = self.Policy.get_client_policy(client, scope, action, realm, user)
res["allowed"] = len(pol) > 0
res["policy"] = pol
if len(pol) > 0:
c.audit['info'] = "allowed by policy %s" % pol.keys()
c.audit['action_detail'] = "action = %s, realm = %s, scope = %s"\
% (action, realm, scope)
c.audit['success'] = True
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
log.error("error checking policy: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
##########################################################################
@log_with(log)
def getPolicy(self, action, **params):
"""
method:
system/getPolicy
description:
this function is used to retrieve the policies that you
defined.