当前位置: 首页>>代码示例>>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;未经允许,请勿转载。