當前位置: 首頁>>代碼示例>>Python>>正文


Python IdResolver.get_serverpool方法代碼示例

本文整理匯總了Python中privacyidea.lib.resolvers.LDAPIdResolver.IdResolver.get_serverpool方法的典型用法代碼示例。如果您正苦於以下問題:Python IdResolver.get_serverpool方法的具體用法?Python IdResolver.get_serverpool怎麽用?Python IdResolver.get_serverpool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在privacyidea.lib.resolvers.LDAPIdResolver.IdResolver的用法示例。


在下文中一共展示了IdResolver.get_serverpool方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_07_get_serverpool

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import get_serverpool [as 別名]
    def test_07_get_serverpool(self):
        timeout = 5
        urilist = "ldap://themis"
        server_pool = LDAPResolver.get_serverpool(urilist, timeout)
        self.assertEqual(len(server_pool), 1)
        self.assertEqual(server_pool.active, True)
        self.assertEqual(server_pool.exhaust, True)
        self.assertEqual(server_pool.strategy, "ROUND_ROBIN")

        urilist = "ldap://themis, ldap://server2"
        server_pool = LDAPResolver.get_serverpool(urilist, timeout)
        self.assertEqual(len(server_pool), 2)
        self.assertEqual(server_pool.servers[0].name, "ldap://themis:389")
        self.assertEqual(server_pool.servers[1].name, "ldap://server2:389")

        urilist = "ldap://themis, ldaps://server2"
        server_pool = LDAPResolver.get_serverpool(urilist, timeout)
        self.assertEqual(len(server_pool), 2)
        self.assertEqual(server_pool.servers[0].name, "ldap://themis:389")
        self.assertEqual(server_pool.servers[1].name, "ldaps://server2:636")
開發者ID:woddx,項目名稱:privacyidea,代碼行數:22,代碼來源:test_lib_resolver.py

示例2: testconnection

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import get_serverpool [as 別名]
    def testconnection(params):
        """
        Test if the given filename exists.

        :param params:
        :return:
        """
        success = False
        ldap_uri = params.get("LDAPURI")
        if is_true(params.get("TLS_VERIFY")) \
                and (ldap_uri.lower().startswith("ldaps") or
                                    params.get("START_TLS")):
            tls_ca_file = params.get("TLS_CA_FILE") or DEFAULT_CA_FILE
            tls_context = Tls(validate=ssl.CERT_REQUIRED,
                              version=ssl.PROTOCOL_TLSv1,
                              ca_certs_file=tls_ca_file)
        else:
            tls_context = None
        try:
            server_pool = IdResolver.get_serverpool(ldap_uri,
                                                    float(params.get(
                                                        "TIMEOUT", 5)),
                                                    tls_context=tls_context)
            l = IdResolver.create_connection(authtype=\
                                                 params.get("AUTHTYPE",
                                                            AUTHTYPE.SIMPLE),
                                             server=server_pool,
                                             user=params.get("BINDDN"),
                                             password=params.get("BINDPW"),
                                             auto_referrals=not params.get(
                                                 "NOREFERRALS"),
                                             start_tls=params.get("START_TLS", False))
            if not l.bind():
                raise Exception("Wrong credentials")
            # search for users...
            l.search(search_base=params["LDAPBASE"],
                     search_scope=ldap3.SUBTREE,
                     search_filter="(&" + params["SEARCHFILTER"] + ")",
                     attributes=[ params["HOSTNAMEATTRIBUTE"] ])

            count = len([x for x in l.response if x.get("type") ==
                         "searchResEntry"])
            desc = _("Your LDAP config seems to be OK, %i machine objects "
                     "found.")\
                % count

            l.unbind()
            success = True

        except Exception as e:
            desc = "{0!r}".format(e)

        return success, desc
開發者ID:STRML,項目名稱:privacyidea,代碼行數:55,代碼來源:ldap.py

示例3: _bind

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import get_serverpool [as 別名]
 def _bind(self):
     if not self.i_am_bound:
         server_pool = IdResolver.get_serverpool(self.uri, self.timeout)
         self.l = IdResolver.create_connection(authtype=self.authtype,
                                               server=server_pool,
                                               user=self.binddn,
                                               password=self.bindpw,
                                               auto_referrals=not
                                               self.noreferrals)
         self.l.open()
         if not self.l.bind():
             raise Exception("Wrong credentials")
         self.i_am_bound = True
開發者ID:Andrew8305,項目名稱:privacyidea,代碼行數:15,代碼來源:ldap.py

示例4: testconnection

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import get_serverpool [as 別名]
    def testconnection(params):
        """
        Test if the given filename exists.

        :param params:
        :return:
        """
        success = False
        try:
            server_pool = IdResolver.get_serverpool(params.get("LDAPURI"),
                                                    float(params.get(
                                                        "TIMEOUT", 5)))
            l = IdResolver.create_connection(authtype=\
                                                 params.get("AUTHTYPE",
                                                            AUTHTYPE.SIMPLE),
                                             server=server_pool,
                                             user=params.get("BINDDN"),
                                             password=params.get("BINDPW"),
                                             auto_referrals=not params.get(
                                                 "NOREFERRALS"))
            l.open()
            if not l.bind():
                raise Exception("Wrong credentials")
            # search for users...
            l.search(search_base=params["LDAPBASE"],
                     search_scope=ldap3.SUBTREE,
                     search_filter="(&" + params["SEARCHFILTER"] + ")",
                     attributes=[ params["HOSTNAMEATTRIBUTE"] ])

            count = len([x for x in l.response if x.get("type") ==
                         "searchResEntry"])
            desc = _("Your LDAP config seems to be OK, %i machine objects "
                     "found.")\
                % count

            l.unbind()
            success = True

        except Exception as e:
            desc = "{0!r}".format(e)

        return success, desc
開發者ID:Andrew8305,項目名稱:privacyidea,代碼行數:44,代碼來源:ldap.py


注:本文中的privacyidea.lib.resolvers.LDAPIdResolver.IdResolver.get_serverpool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。