当前位置: 首页>>代码示例>>Python>>正文


Python user.User类代码示例

本文整理汇总了Python中privacyidea.lib.user.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_11_get_search_fields

 def test_11_get_search_fields(self):
     user = User(login="cornelius", realm=self.realm1)
     sF = user.get_search_fields()
     self.assertTrue(self.resolvername1 in sF, sF)
     resolver_sF = sF.get(self.resolvername1)
     self.assertTrue("username" in resolver_sF, resolver_sF)
     self.assertTrue("userid" in resolver_sF, resolver_sF)
开发者ID:MWelp,项目名称:privacyidea,代码行数:7,代码来源:test_lib_user.py

示例2: test_02_get_user_identifiers

 def test_02_get_user_identifiers(self):
     user = User(login="root",
                 realm=self.realm1)
     (uid, rtype, resolvername) = user.get_user_identifiers()
     self.assertTrue(uid == "0", uid)
     self.assertTrue(rtype == "passwdresolver", rtype)
     self.assertTrue(resolvername == self.resolvername1, resolvername)
开发者ID:MWelp,项目名称:privacyidea,代码行数:7,代码来源:test_lib_user.py

示例3: test_14_create_delete_user

    def test_14_create_delete_user(self):
        realm = "sqlrealm"
        resolver = "SQL1"
        parameters = self.parameters
        parameters["resolver"] = resolver
        parameters["type"] = "sqlresolver"

        rid = save_resolver(parameters)
        self.assertTrue(rid > 0, rid)

        (added, failed) = set_realm(realm, [resolver])
        self.assertEqual(len(failed), 0)
        self.assertEqual(len(added), 1)

        # Create the user
        uid = create_user(resolver, {"username": "achmed3",
                                     "givenname": "achmed"},
                                     password="secret")
        self.assertTrue(uid > 6)

        user = User("achmed3", realm=realm)
        r = user.check_password("secret")

        # delete user
        r = user.delete()
        self.assertTrue(r)
开发者ID:MWelp,项目名称:privacyidea,代码行数:26,代码来源:test_lib_user.py

示例4: test_13_update_user

    def test_13_update_user(self):
        realm = "sqlrealm"
        resolver = "SQL1"
        parameters = self.parameters
        parameters["resolver"] = resolver
        parameters["type"] = "sqlresolver"

        rid = save_resolver(parameters)
        self.assertTrue(rid > 0, rid)

        (added, failed) = set_realm(realm, [resolver])
        self.assertEqual(len(failed), 0)
        self.assertEqual(len(added), 1)

        user = User(login="wordpressuser", realm=realm)
        uinfo = user.info
        self.assertEqual(uinfo.get("givenname", ""), "")

        user.update_user_info({"givenname": "wordy",
                               "username": "WordpressUser"})
        uinfo = user.info
        self.assertEqual(uinfo.get("givenname"), "wordy")

        self.assertEqual(user.login, "WordpressUser")

        user.update_user_info({"givenname": "",
                               "username": "wordpressuser"})
开发者ID:MWelp,项目名称:privacyidea,代码行数:27,代码来源:test_lib_user.py

示例5: test_09_invalidate_edit_user

    def test_09_invalidate_edit_user(self):
        # Validate that editing users actually invalidates the cache. For that, we first need an editable resolver
        self._create_sql_realm()
        # The cache is initially empty
        self.assertEquals(UserCache.query.count(), 0)
        # The following adds an entry to the cache
        user = User(login="wordpressuser", realm=self.sql_realm)
        self.assertEquals(UserCache.query.count(), 1)
        uinfo = user.info
        self.assertEqual(uinfo.get("givenname", ""), "")

        user.update_user_info({"givenname": "wordy"})
        uinfo = user.info
        self.assertEqual(uinfo.get("givenname"), "wordy")
        # This should have removed the entry from the cache
        self.assertEqual(UserCache.query.count(), 0)
        # But now it gets added again
        user2 = User(login="wordpressuser", realm=self.sql_realm)
        self.assertEqual(UserCache.query.count(), 1)
        # Change it back for the other tests
        user.update_user_info({"givenname": ""})
        uinfo = user.info
        self.assertEqual(uinfo.get("givenname", ""), "")
        self.assertEqual(UserCache.query.count(), 0)
        self._delete_sql_realm()
开发者ID:STRML,项目名称:privacyidea,代码行数:25,代码来源:test_lib_usercache.py

示例6: test_16_ordered_resolver

    def test_16_ordered_resolver(self):
        rid = save_resolver({"resolver": "resolver2",
                             "type": "passwdresolver",
                             "fileName": PWFILE})
        rid = save_resolver({"resolver": "reso4",
                             "type": "passwdresolver",
                             "fileName": PWFILE})

        (added, failed) = set_realm("sort_realm",
                                    ["resolver1", "resolver2", "reso3",
                                     "reso4"],
                                    priority={"resolver1": 30,
                                              "resolver2": 10,
                                              "reso3": 27,
                                              "reso4": 5})

        self.assertTrue(len(failed) == 0)
        self.assertTrue(len(added) == 4)

        root = User("root", "sort_realm")
        r = root.get_ordererd_resolvers()
        self.assertEqual(r[0], "reso4")
        self.assertEqual(r[1], "resolver2")
        self.assertEqual(r[2], "reso3")
        self.assertEqual(r[3], "resolver1")

        delete_realm("sort_realm")
开发者ID:MWelp,项目名称:privacyidea,代码行数:27,代码来源:test_lib_user.py

示例7: test_00_create_user

 def test_00_create_user(self):
     rid = save_resolver({"resolver": self.resolvername1,
                          "type": "passwdresolver",
                          "fileName": PWFILE})
     self.assertTrue(rid > 0, rid)
            
     (added, failed) = set_realm(self.realm1,
                                 [self.resolvername1])
     self.assertTrue(len(failed) == 0)
     self.assertTrue(len(added) == 1)
     
     user = User(login="root",
                 realm=self.realm1,
                 resolver=self.resolvername1)
     
     user_str = "{0!s}".format(user)
     self.assertTrue(user_str == "<[email protected]>", user_str)
     # check proper unicode() and str() handling
     self.assertIsInstance(str(user), bytes)
     self.assertIsInstance(unicode(user), unicode)
     
     self.assertFalse(user.is_empty())
     self.assertTrue(User().is_empty())
     
     user_repr = "{0!r}".format(user)
     expected = "User(login='root', realm='realm1', resolver='resolver1')"
     self.assertTrue(user_repr == expected, user_repr)
开发者ID:STRML,项目名称:privacyidea,代码行数:27,代码来源:test_lib_user.py

示例8: setUp_user_realm2

    def setUp_user_realm2(self):
        # create user realm
        rid = save_resolver({"resolver": self.resolvername1,
                             "type": "passwdresolver",
                             "fileName": PWFILE})
        self.assertTrue(rid > 0, rid)

        (added, failed) = set_realm(self.realm2,
                                    [self.resolvername1])
        self.assertTrue(len(failed) == 0)
        self.assertTrue(len(added) == 1)

        user = User(login="root",
                    realm=self.realm2,
                    resolver=self.resolvername1)

        user_str = "{0!s}".format(user)
        self.assertTrue(user_str == "<[email protected]>", user_str)

        self.assertFalse(user.is_empty())
        self.assertTrue(User().is_empty())

        user_repr = "{0!r}".format(user)
        expected = "User(login='root', realm='realm2', resolver='resolver1')"
        self.assertTrue(user_repr == expected, user_repr)
开发者ID:salvorapi,项目名称:privacyidea,代码行数:25,代码来源:base.py

示例9: auth_otppin

def auth_otppin(wrapped_function, *args, **kwds):
    """
    Decorator to decorate the tokenclass.check_pin function.
    Depending on the ACTION.OTPPIN it
    * either simply accepts an empty pin
    * checks the pin against the userstore
    * or passes the request to the wrapped_function

    :param wrapped_function: In this case the wrapped function should be
    tokenclass.check_ping
    :param *args: args[1] is the pin
    :param **kwds: kwds["options"] contains the flask g
    :return: True or False
    """
    # if tokenclass.check_pin is called in any other way, options may be None
    #  or it might have no element "g".
    options = kwds.get("options") or {}
    g = options.get("g")
    if g:
        token = args[0]
        pin = args[1]
        clientip = options.get("clientip")
        user_object = kwds.get("user")
        if not user_object:
            # No user in the parameters, so we need to determine the owner of
            #  the token
            user_object = token.user
            realms = token.get_realms()
            if not user_object and len(realms):
                # if the token has not owner, we take a realm.
                user_object = User("", realm=realms[0])
        if not user_object:
            # If we still have no user and no tokenrealm, we create an empty
            # user object.
            user_object=User("", realm="")
        # get the policy
        policy_object = g.policy_object
        otppin_dict = policy_object.get_action_values(ACTION.OTPPIN,
                                                      scope=SCOPE.AUTH,
                                                      realm=user_object.realm,
                                                      resolver=user_object.resolver,
                                                      user=user_object.login,
                                                      client=clientip,
                                                      unique=True,
                                                      audit_data=g.audit_object.audit_data)
        if otppin_dict:
            if list(otppin_dict)[0] == ACTIONVALUE.NONE:
                if pin == "":
                    # No PIN checking, we expect an empty PIN!
                    return True
                else:
                    return False

            if list(otppin_dict)[0] == ACTIONVALUE.USERSTORE:
                rv = user_object.check_password(pin)
                return rv is not None

    # call and return the original check_pin function
    return wrapped_function(*args, **kwds)
开发者ID:privacyidea,项目名称:privacyidea,代码行数:59,代码来源:policydecorators.py

示例10: test_01_resolvers_of_user

    def test_01_resolvers_of_user(self):
        user = User(login="root",
                    realm=self.realm1)

        resolvers = user.get_resolvers()
        self.assertTrue(self.resolvername1 in resolvers, resolvers)
        self.assertFalse(self.resolvername2 in resolvers, resolvers)
        
        user2 = User(login="root",
                     realm=self.realm1,
                     resolver=self.resolvername1)
        resolvers = user2.get_resolvers()
        self.assertTrue(self.resolvername1 in resolvers, resolvers)
        self.assertFalse(self.resolvername2 in resolvers, resolvers)
开发者ID:MWelp,项目名称:privacyidea,代码行数:14,代码来源:test_lib_user.py

示例11: test_10_invalidate_delete_user

 def test_10_invalidate_delete_user(self):
     # Validate that deleting users actually invalidates the cache. For that, we first need an editable resolver
     self._create_sql_realm()
     # The cache is initially empty
     self.assertEquals(UserCache.query.count(), 0)
     # The following adds an entry to the cache
     user = User(login="wordpressuser", realm=self.sql_realm)
     self.assertEquals(UserCache.query.count(), 1)
     uinfo = user.info
     user.delete()
     # This should have removed the entry from the cache
     self.assertEqual(UserCache.query.count(), 0)
     # We add the user again for the other tests
     create_user(self.sql_resolver, uinfo)
     self.assertEqual(UserCache.query.count(), 0)
     self._delete_sql_realm()
开发者ID:STRML,项目名称:privacyidea,代码行数:16,代码来源:test_lib_usercache.py

示例12: test_03_get_identifiers

    def test_03_get_identifiers(self):
        # create realm
        self._create_realm()
        # delete user_cache
        r = delete_user_cache()
        self.assertTrue(r >= 0)

        # The username is not in the cache. It is fetched from the resolver
        # At the same time the cache is filled. Implicitly we test the
        # _get_resolvers!
        user = User(self.username, self.realm1, self.resolvername1)
        uids = user.get_user_identifiers()
        self.assertEqual(user.login, self.username)
        self.assertEqual(user.uid, self.uid)

        # Now, the cache should have exactly one entry
        entry = UserCache.query.one()
        self.assertEqual(entry.user_id, self.uid)
        self.assertEqual(entry.username, self.username)
        self.assertEqual(entry.resolver, self.resolvername1)

        # delete the resolver, which also purges the cache
        self._delete_realm()

        # manually re-add the entry from above
        UserCache(entry.username, entry.resolver, entry.user_id, entry.timestamp).save()

        # the username is fetched from the cache
        u_name = get_username(self.uid, self.resolvername1)
        self.assertEqual(u_name, self.username)

        # The `User` class also fetches the UID from the cache
        user2 = User(self.username, self.realm1, self.resolvername1)
        self.assertEqual(user2.uid, self.uid)

        # delete the cache
        r = delete_user_cache()

        # try to fetch the username. It is not in the cache and the
        # resolver does not exist anymore.
        u_name = get_username(self.uid, self.resolvername1)
        self.assertEqual(u_name, "")

        # similar case for the `User` class
        # The `User` class also tries to fetch the UID from the cache
        with self.assertRaises(UserError):
            user3 = User(self.username, self.realm1, self.resolvername1)
开发者ID:STRML,项目名称:privacyidea,代码行数:47,代码来源:test_lib_usercache.py

示例13: test_00_create_user_realm

    def test_00_create_user_realm(self):
        rid = save_resolver({"resolver": self.resolvername1, "type": "passwdresolver", "fileName": PWFILE})
        self.assertTrue(rid > 0, rid)

        (added, failed) = set_realm(self.realm1, [self.resolvername1])
        self.assertTrue(len(failed) == 0)
        self.assertTrue(len(added) == 1)

        user = User(login="root", realm=self.realm1, resolver=self.resolvername1)

        user_str = "%s" % user
        self.assertTrue(user_str == "<[email protected]>", user_str)

        self.assertFalse(user.is_empty())
        self.assertTrue(User().is_empty())

        user_repr = "%r" % user
        expected = "User(login='root', realm='realm1', resolver='resolver1')"
        self.assertTrue(user_repr == expected, user_repr)
开发者ID:tongwen-it,项目名称:privacyidea,代码行数:19,代码来源:test_lib_tokens_daplug.py

示例14: update_user

def update_user():
    """
    Edit a user in the user store.
    The resolver must have the flag editable, so that the user can be deleted.
    Only administrators are allowed to edit users.

    **Example request**:

    .. sourcecode:: http

       PUT /user
       user=existing_user
       resolver=<resolvername>
       surname=...
       givenname=...
       email=...
       mobile=...
       phone=...
       password=...
       description=...

       Host: example.com
       Accept: application/json

    .. note:: Also a user can call this function to e.g. change his password.
       But in this case the parameter "user" and "resolver" get overwritten
       by the values of the authenticated user, even if he specifies another
       username.
    """
    attributes = _get_attributes_from_param(request.all_data)
    username = getParam(request.all_data, "user", optional=False)
    resolvername = getParam(request.all_data, "resolver", optional=False)
    user_obj = User(login=username, resolver=resolvername)
    # Remove the password from the attributes, so that we can hide it in the
    # logs
    password = attributes.get("password")
    if password:
        del attributes["password"]
    r = user_obj.update_user_info(attributes, password=password)
    g.audit_object.log({"success": True,
                        "info": u"{0!s}: {1!s}/{2!s}".format(r, username, resolvername)})
    return send_result(r)
开发者ID:STRML,项目名称:privacyidea,代码行数:42,代码来源:user.py

示例15: delete_user

def delete_user(resolvername=None, username=None):
    """
    Delete a User in the user store.
    The resolver must have the flag editable, so that the user can be deleted.
    Only administrators are allowed to delete users.

    Delete a user object in a user store by calling

    **Example request**:

    .. sourcecode:: http

       DELETE /user/<resolvername>/<username>
       Host: example.com
       Accept: application/json

    """
    user_obj = User(login=username, resolver=resolvername)
    res = user_obj.delete()
    g.audit_object.log({"success": res,
                        "info": u"{0!s}".format(user_obj)})
    return send_result(res)
开发者ID:STRML,项目名称:privacyidea,代码行数:22,代码来源:user.py


注:本文中的privacyidea.lib.user.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。