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