本文整理汇总了Python中privacyidea.lib.policy.PolicyClass.ui_get_rights方法的典型用法代码示例。如果您正苦于以下问题:Python PolicyClass.ui_get_rights方法的具体用法?Python PolicyClass.ui_get_rights怎么用?Python PolicyClass.ui_get_rights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类privacyidea.lib.policy.PolicyClass
的用法示例。
在下文中一共展示了PolicyClass.ui_get_rights方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_17_ui_get_rights
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import ui_get_rights [as 别名]
def test_17_ui_get_rights(self):
P = PolicyClass()
logged_in_user = {"username": "admin", "role": "admin", "realm": "realm1"}
# Without policies, the admin gets all
rights = P.ui_get_rights(SCOPE.ADMIN, "realm1", "admin")
self.assertEqual(len(rights), 39)
# An admin may only enroll Yubikeys
set_policy(name="tokenEnroll", scope=SCOPE.ADMIN, action="enrollYUBIKEY")
P = PolicyClass()
rights = P.ui_get_rights(SCOPE.ADMIN, "realm1", "admin")
self.assertEqual(rights, ["enrollYUBIKEY"])
# A user may do something else...
set_policy(name="userpol", scope=SCOPE.USER, action="enable")
P = PolicyClass()
rights = P.ui_get_rights(SCOPE.USER, "realm2", "user")
# there was still another policy...
self.assertEqual(rights, ["enable", "disable"])
示例2: test_17_ui_get_rights
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import ui_get_rights [as 别名]
def test_17_ui_get_rights(self):
P = PolicyClass()
# Without policies, the admin gets all
rights = P.ui_get_rights(SCOPE.ADMIN, "realm1", "admin")
self.assertTrue(len(rights) >= 60)
# An admin may only enroll Yubikeys
set_policy(name="tokenEnroll", scope=SCOPE.ADMIN,
action="enrollYUBIKEY")
P = PolicyClass()
rights = P.ui_get_rights(SCOPE.ADMIN, "realm1", "admin")
self.assertEqual(rights, ["enrollYUBIKEY"])
# A user may do something else...
set_policy(name="userpol", scope=SCOPE.USER, action="enable")
P = PolicyClass()
rights = P.ui_get_rights(SCOPE.USER, "realm2", "user")
# there was still another policy...
self.assertEqual(rights, ["enable", "disable"])
delete_policy("tokenEnroll")
delete_policy("userpol")
# Two admins:
# adminA is allowed to enroll tokens in all realms
# adminB is allowed to enroll tokens only in realmB
set_policy(name="polAdminA", scope=SCOPE.ADMIN, user="adminA",
action="enrollHOTP, enrollTOTP")
set_policy(name="polAdminB", scope=SCOPE.ADMIN, user="adminB",
realm="realmB",
action="enrollHOTP")
P = PolicyClass()
# realm is empty, since in case of an admin, this is the admin realm
rights = P.ui_get_rights(SCOPE.ADMIN, realm=None, username="adminA")
self.assertTrue("enrollTOTP" in rights)
self.assertTrue("enrollHOTP" in rights)
rights = P.ui_get_rights(SCOPE.ADMIN, realm=None, username="adminB")
self.assertTrue("enrollTOTP" not in rights)
self.assertTrue("enrollHOTP" in rights)
rights = P.ui_get_rights(SCOPE.ADMIN, realm=None, username="adminC")
self.assertEqual(rights, [])
delete_policy("polAdminA")
delete_policy("polAdminB")