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


Python IdResolver.split_uri方法代碼示例

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


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

示例1: test_06_slit_uri

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import split_uri [as 別名]
    def test_06_slit_uri(self):
        uri = "ldap://server"
        server, port, ssl = LDAPResolver.split_uri(uri)
        self.assertEqual(ssl, False)
        self.assertEqual(server, "server")
        self.assertEqual(port, None)

        uri = "ldap://server:389"
        server, port, ssl = LDAPResolver.split_uri(uri)
        self.assertEqual(ssl, False)
        self.assertEqual(server, "server")
        self.assertEqual(port, 389)

        uri = "ldaps://server:389"
        server, port, ssl = LDAPResolver.split_uri(uri)
        self.assertEqual(ssl, True)
        self.assertEqual(server, "server")
        self.assertEqual(port, 389)

        uri = "ldaps://server"
        server, port, ssl = LDAPResolver.split_uri(uri)
        self.assertEqual(ssl, True)
        self.assertEqual(server, "server")
        self.assertEqual(port, None)

        uri = "server"
        server, port, ssl = LDAPResolver.split_uri(uri)
        self.assertEqual(ssl, False)
        self.assertEqual(server, "server")
        self.assertEqual(port, None)
開發者ID:woddx,項目名稱:privacyidea,代碼行數:32,代碼來源:test_lib_resolver.py

示例2: testconnection

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

        :param params:
        :return:
        """
        success = False
        try:
            (host, port, ssl) = IdResolver.split_uri(params.get("LDAPURI"))
            server = ldap3.Server(host, port=port,
                                  use_ssl=ssl,
                                  connect_timeout=float(params.get("TIMEOUT",
                                                                  5)))
            l = IdResolver.create_connection(authtype=\
                                                 params.get("AUTHTYPE",
                                                            AUTHTYPE.SIMPLE),
                                             server=server,
                                             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 = "%r" % e

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

示例3: load_config

# 需要導入模塊: from privacyidea.lib.resolvers.LDAPIdResolver import IdResolver [as 別名]
# 或者: from privacyidea.lib.resolvers.LDAPIdResolver.IdResolver import split_uri [as 別名]
    def load_config(self, config):
        """
        This loads the configuration dictionary, which contains the necessary
        information for the machine resolver to find and connect to the
        machine store.

        class=computer or sAMAccountType=805306369 (MachineAccount)
        * hostname: attribute dNSHostName
        * id: DN or objectSid
        * ip: N/A

        :param config: The configuration dictionary to run the machine resolver
        :type config: dict
        :return: None
        """
        self.uri = config.get("LDAPURI")
        if self.uri is None:
            raise MachineResolverError("LDAPURI is missing!")
        (self.server, self.port, self.ssl) = IdResolver.split_uri(self.uri)
        self.basedn = config.get("LDAPBASE")
        if self.basedn is None:
            raise MachineResolverError("LDAPBASE is missing!")
        self.binddn = config.get("BINDDN")
        self.bindpw = config.get("BINDPW")
        self.timeout = float(config.get("TIMEOUT", 5))
        self.sizelimit = config.get("SIZELIMIT", 500)
        self.hostname_attribute = config.get("HOSTNAMEATTRIBUTE")
        self.id_attribute = config.get("IDATTRIBUTE", "DN")
        self.ip_attribute = config.get("IPATTRIBUTE")
        self.search_filter = config.get("SEARCHFILTER",
                                        "(objectClass=computer)")
        self.reverse_map = {self.ip_attribute: "ip",
                            self.hostname_attribute: "hostname",
                            self.id_attribute: "id"}
        self.noreferrals = config.get("NOREFERRALS", False)
        self.certificate = config.get("CACERTIFICATE")
        self.authtype = config.get("AUTHTYPE", AUTHTYPE.SIMPLE)
開發者ID:XCage15,項目名稱:privacyidea,代碼行數:39,代碼來源:ldap.py


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