本文整理汇总了Python中ldap.OPT_NETWORK_TIMEOUT属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.OPT_NETWORK_TIMEOUT属性的具体用法?Python ldap.OPT_NETWORK_TIMEOUT怎么用?Python ldap.OPT_NETWORK_TIMEOUT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.OPT_NETWORK_TIMEOUT属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_NETWORK_TIMEOUT [as 别名]
def __enter__(self):
trace_level = 2 if os.environ.get("USERS_DEBUG") == "1" else 0
self._conn = ldap.initialize(self._ldap_uri, trace_level=trace_level)
self._conn.set_option(ldap.OPT_REFERRALS, 1)
self._conn.set_option(
ldap.OPT_NETWORK_TIMEOUT, self._network_timeout or _DEFAULT_NETWORK_TIMEOUT
)
self._conn.set_option(ldap.OPT_TIMEOUT, self._timeout or _DEFAULT_TIMEOUT)
if self._allow_tls_fallback:
logger.debug("TLS Fallback enabled in LDAP")
self._conn.set_option(ldap.OPT_X_TLS_TRY, 1)
self._conn.simple_bind_s(self._user_dn, self._user_pw)
return self._conn
示例2: initialize
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_NETWORK_TIMEOUT [as 别名]
def initialize(self):
"""Initialize a connection to the LDAP server.
:return: LDAP connection object.
"""
try:
conn = ldap.initialize('{0}://{1}:{2}'.format(
current_app.config['LDAP_SCHEMA'],
current_app.config['LDAP_HOST'],
current_app.config['LDAP_PORT']))
conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
current_app.config['LDAP_TIMEOUT'])
conn = self._set_custom_options(conn)
conn.protocol_version = ldap.VERSION3
if current_app.config['LDAP_USE_TLS']:
conn.start_tls_s()
return conn
except ldap.LDAPError as e:
raise LDAPException(self.error(e.args))
示例3: _get_conn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_NETWORK_TIMEOUT [as 别名]
def _get_conn(self):
self._log.debug('Setting up LDAP connection')
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
try:
conn = ldap.initialize(self._url)
conn.set_option(ldap.OPT_NETWORK_TIMEOUT, 3)
conn.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
conn.simple_bind_s(self._binddn, self._bindpw)
except (
ldap.SERVER_DOWN,
ldap.NO_SUCH_OBJECT,
ldap.INVALID_CREDENTIALS
) as e:
if hasattr(e, 'message') and 'desc' in e.message:
msg = e.message['desc']
else:
msg = e.args[0]['desc']
self._log.debug('%s (%s)' % (msg, self._url))
return False
self._log.debug('LDAP connection established')
return conn
示例4: find_ldap_user
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_NETWORK_TIMEOUT [as 别名]
def find_ldap_user(login):
'''Find the LDAP user identified by 'login' in the configured ldap database
:param login: The login to find in the LDAP database
:returns: None if no user is found, a dictionary defining 'cn', 'username',
'fullname' and 'email otherwise.
'''
cnx = ldap.initialize(toolkit.config[u'ckanext.ldap.uri'], bytes_mode=False,
trace_level=toolkit.config[u'ckanext.ldap.trace_level'])
cnx.set_option(ldap.OPT_NETWORK_TIMEOUT, 10)
if toolkit.config.get(u'ckanext.ldap.auth.dn'):
try:
if toolkit.config[u'ckanext.ldap.auth.method'] == u'SIMPLE':
cnx.bind_s(toolkit.config[u'ckanext.ldap.auth.dn'],
toolkit.config[u'ckanext.ldap.auth.password'])
elif toolkit.config[u'ckanext.ldap.auth.method'] == u'SASL':
if toolkit.config[u'ckanext.ldap.auth.mechanism'] == u'DIGEST-MD5':
auth_tokens = ldap.sasl.digest_md5(toolkit.config[u'ckanext.ldap.auth.dn'],
toolkit.config[
u'ckanext.ldap.auth.password'])
cnx.sasl_interactive_bind_s(u'', auth_tokens)
else:
log.error(u'SASL mechanism not supported: {0}'.format(
toolkit.config[u'ckanext.ldap.auth.mechanism']))
return None
else:
log.error(u'LDAP authentication method is not supported: {0}'.format(
toolkit.config[u'ckanext.ldap.auth.method']))
return None
except ldap.SERVER_DOWN:
log.error(u'LDAP server is not reachable')
return None
except ldap.INVALID_CREDENTIALS:
log.error(
u'LDAP server credentials (ckanext.ldap.auth.dn and ckanext.ldap.auth.password) '
u'invalid')
return None
except ldap.LDAPError, e:
log.error(u'Fatal LDAP Error: {0}'.format(e))
return None