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


Python ldap.OPT_X_TLS_CACERTFILE屬性代碼示例

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


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

示例1: test_connect_defaults

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import OPT_X_TLS_CACERTFILE [as 別名]
def test_connect_defaults(self):
        """
        Connect with default arguments.
        """
        service = self.service()
        with TestService.Connection(service, "query") as connection:

            self.assertEquals(connection.methods_called(), ["initialize"])

            for option in (
                ldap.OPT_TIMEOUT,
                ldap.OPT_X_TLS_CACERTFILE,
                ldap.OPT_X_TLS_CACERTDIR,
                ldap.OPT_DEBUG_LEVEL,
            ):
                self.assertRaises(KeyError, connection.get_option, option)

            self.assertFalse(connection.tls_enabled) 
開發者ID:apple,項目名稱:ccs-twistedextensions,代碼行數:20,代碼來源:test_service.py

示例2: get_connection

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import OPT_X_TLS_CACERTFILE [as 別名]
def get_connection(self, bind_dn=None, password=None):
        """Return an LDAP object."""
        if not LdapFactory.is_enabled():
            raise LdapNotEnabledException('Ldap has not been configured on this node')

        ca_cert_exists = os.path.exists(self.ldap_ca_cert_path)
        ldap_config = MCVirtConfig().get_config()['ldap']

        ldap.set_option(
            ldap.OPT_X_TLS_CACERTFILE,
            self.ldap_ca_cert_path if ca_cert_exists else ''
        )

        if bind_dn is None and password is None:
            bind_dn = ldap_config['bind_dn']
            password = ldap_config['bind_pass']

        try:
            ldap_connection = ldap.initialize(uri=ldap_config['server_uri'])
            try:
                ldap_connection.bind_s(bind_dn, password)
            except AttributeError:
                # This is required for the mockldap server as part of the unit tests
                ldap_connection.simple_bind_s(bind_dn, password)
        except Exception:
            raise LdapConnectionFailedException(
                'Connection attempts to the LDAP server failed.'
            )

        return ldap_connection 
開發者ID:ITDevLtd,項目名稱:MCVirt,代碼行數:32,代碼來源:ldap_factory.py

示例3: test_connect_withOptions

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import OPT_X_TLS_CACERTFILE [as 別名]
def test_connect_withOptions(self):
        """
        Connect with default arguments.
        """
        service = self.service(
            timeout=18,
            tlsCACertificateFile=FilePath("/path/to/cert"),
            tlsCACertificateDirectory=FilePath("/path/to/certdir"),
            _debug=True,
        )
        with TestService.Connection(service, "query") as connection:

            self.assertEquals(
                connection.methods_called(),
                [
                    "initialize",
                    "set_option", "set_option", "set_option", "set_option",
                ]
            )

            opt = lambda k: connection.get_option(k)

            self.assertEquals(opt(ldap.OPT_TIMEOUT), 18)
            self.assertEquals(opt(ldap.OPT_X_TLS_CACERTFILE), "/path/to/cert")
            self.assertEquals(opt(ldap.OPT_X_TLS_CACERTDIR), "/path/to/certdir")
            self.assertEquals(opt(ldap.OPT_DEBUG_LEVEL), 255)

            # Tested in test_connect_defaults, but test again here since we're
            # setting SSL options and we want to be sure they don't somehow enable
            # SSL implicitly.
            self.assertFalse(connection.tls_enabled) 
開發者ID:apple,項目名稱:ccs-twistedextensions,代碼行數:33,代碼來源:test_service.py

示例4: init_ldap

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import OPT_X_TLS_CACERTFILE [as 別名]
def init_ldap(ldap_server=server,
                  ldap_port=port,
                  ldap_basedn=base_dn,
                  ldap_mode=mode,
                  secure=secure,
                  cert_path=cert_path,
                  cert_file=cert_file):
        """
        Inicialize ldap connection
        """
        logger.info('[%s] Initialize ldap connection' % str(ldap_server))
        if secure:
            if not ldap_port:
                ldap_port = 636
            con = ldap.initialize(
                "ldaps://" + ldap_server + ":" + str(ldap_port))
            if cert_path:
                con.set_option(ldap.OPT_X_TLS_CACERTDIR, cert_path)
            if cert_file:
                con.set_option(ldap.OPT_X_TLS_CACERTFILE, cert_file)
        else:
            if not ldap_port:
                ldap_port = 389
            con = ldap.initialize(
                "ldap://" + ldap_server + ":" + str(ldap_port))
        return con 
開發者ID:uwdata,項目名稱:termite-visualizations,代碼行數:28,代碼來源:ldap_auth.py


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