本文整理汇总了Python中privacyidea.lib.policy.PolicyClass.ui_get_enroll_tokentypes方法的典型用法代码示例。如果您正苦于以下问题:Python PolicyClass.ui_get_enroll_tokentypes方法的具体用法?Python PolicyClass.ui_get_enroll_tokentypes怎么用?Python PolicyClass.ui_get_enroll_tokentypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类privacyidea.lib.policy.PolicyClass
的用法示例。
在下文中一共展示了PolicyClass.ui_get_enroll_tokentypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_16_admin_realm
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import ui_get_enroll_tokentypes [as 别名]
def test_16_admin_realm(self):
P = PolicyClass()
logged_in_user = {"username": "admin",
"role": "admin",
"realm": "realm1"}
# Without policies, the admin gets all
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertTrue("hotp" in tt)
self.assertTrue("totp" in tt)
self.assertTrue("motp" in tt)
self.assertTrue("sms" in tt)
self.assertTrue("spass" in tt)
self.assertTrue("sshkey" in tt)
self.assertTrue("email" in tt)
self.assertTrue("certificate" in tt)
self.assertTrue("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertTrue("radius" in tt)
# An admin in realm1 may only enroll Yubikeys
set_policy(name="tokenEnroll", scope=SCOPE.ADMIN,
adminrealm="realm1",
action="enrollYUBIKEY")
P = PolicyClass()
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertFalse("hotp" in tt)
self.assertFalse("totp" in tt)
self.assertFalse("motp" in tt)
self.assertFalse("sms" in tt)
self.assertFalse("spass" in tt)
self.assertFalse("sshkey" in tt)
self.assertFalse("email" in tt)
self.assertFalse("certificate" in tt)
self.assertFalse("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertFalse("radius" in tt)
# An admin in another admin realm may enroll nothing.
logged_in_user = {"username": "admin",
"role": "admin",
"realm": "OtherRealm"}
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertFalse("hotp" in tt)
self.assertFalse("totp" in tt)
self.assertFalse("motp" in tt)
self.assertFalse("sms" in tt)
self.assertFalse("spass" in tt)
self.assertFalse("sshkey" in tt)
self.assertFalse("email" in tt)
self.assertFalse("certificate" in tt)
self.assertFalse("yubico" in tt)
self.assertFalse("yubikey" in tt)
self.assertFalse("radius" in tt)
delete_policy("tokenEnroll")
示例2: test_15_ui_tokentypes
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import ui_get_enroll_tokentypes [as 别名]
def test_15_ui_tokentypes(self):
P = PolicyClass()
logged_in_user = {"username": "admin",
"role": "admin",
"realm": "realm1"}
# Without policies, the admin gets all
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertTrue("hotp" in tt)
self.assertTrue("totp" in tt)
self.assertTrue("motp" in tt)
self.assertTrue("sms" in tt)
self.assertTrue("spass" in tt)
self.assertTrue("sshkey" in tt)
self.assertTrue("email" in tt)
self.assertTrue("certificate" in tt)
self.assertTrue("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertTrue("radius" in tt)
# An admin may only enroll Yubikeys
set_policy(name="tokenEnroll", scope=SCOPE.ADMIN,
action="enrollYUBIKEY")
P = PolicyClass()
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertFalse("hotp" in tt)
self.assertFalse("totp" in tt)
self.assertFalse("motp" in tt)
self.assertFalse("sms" in tt)
self.assertFalse("spass" in tt)
self.assertFalse("sshkey" in tt)
self.assertFalse("email" in tt)
self.assertFalse("certificate" in tt)
self.assertFalse("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertFalse("radius" in tt)
# A user may enroll nothing
set_policy(name="someUserAction", scope=SCOPE.USER,
action="disable")
P = PolicyClass()
tt = P.ui_get_enroll_tokentypes("127.0.0.1", {"username": "kurt",
"realm": "realm",
"role": "user"})
self.assertEqual(len(tt), 0)
delete_policy("tokenEnroll")
示例3: test_15_ui_tokentypes
# 需要导入模块: from privacyidea.lib.policy import PolicyClass [as 别名]
# 或者: from privacyidea.lib.policy.PolicyClass import ui_get_enroll_tokentypes [as 别名]
def test_15_ui_tokentypes(self):
P = PolicyClass()
logged_in_user = {"username": "admin",
"role": "admin",
"realm": "realm1"}
# Without policies, the admin gets all
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertTrue("hotp" in tt)
self.assertTrue("totp" in tt)
self.assertTrue("motp" in tt)
self.assertTrue("sms" in tt)
self.assertTrue("spass" in tt)
self.assertTrue("sshkey" in tt)
self.assertTrue("email" in tt)
self.assertTrue("certificate" in tt)
self.assertTrue("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertTrue("radius" in tt)
# An admin may only enroll Yubikeys
set_policy(name="tokenEnroll", scope=SCOPE.ADMIN,
action="enrollYUBIKEY")
P = PolicyClass()
tt = P.ui_get_enroll_tokentypes("127.0.0.1", logged_in_user)
self.assertFalse("hotp" in tt)
self.assertFalse("totp" in tt)
self.assertFalse("motp" in tt)
self.assertFalse("sms" in tt)
self.assertFalse("spass" in tt)
self.assertFalse("sshkey" in tt)
self.assertFalse("email" in tt)
self.assertFalse("certificate" in tt)
self.assertFalse("yubico" in tt)
self.assertTrue("yubikey" in tt)
self.assertFalse("radius" in tt)
# A user may enroll nothing
set_policy(name="someUserAction", scope=SCOPE.USER,
action="disable")
P = PolicyClass()
tt = P.ui_get_enroll_tokentypes("127.0.0.1", {"username": "kurt",
"realm": "realm",
"role": "user"})
self.assertEqual(len(tt), 0)
delete_policy("tokenEnroll")
# 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_enroll_tokentypes(None, {"role": SCOPE.ADMIN,
"realm": None,
"username": "adminA"})
self.assertTrue("hotp" in rights)
self.assertTrue("totp" in rights)
rights = P.ui_get_enroll_tokentypes(None, {"role": SCOPE.ADMIN,
"realm": "",
"username": "adminB"})
self.assertTrue("totp" not in rights)
self.assertTrue("hotp" in rights)
rights = P.ui_get_enroll_tokentypes(None, {"role": SCOPE.ADMIN,
"realm": "",
"username": "adminC"})
self.assertEqual(rights, {})
delete_policy("polAdminA")
delete_policy("polAdminB")