本文整理匯總了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)
示例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
示例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)
示例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