本文整理汇总了Python中ldap.OPT_REFERRALS属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.OPT_REFERRALS属性的具体用法?Python ldap.OPT_REFERRALS怎么用?Python ldap.OPT_REFERRALS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.OPT_REFERRALS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ldap_connect
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def _ldap_connect(self):
"""
Prepare ldap object for binding phase.
"""
try:
connection = ldap.initialize(self._ldap_uri)
connection.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
connection.set_option(ldap.OPT_REFERRALS,
int(self._chase_referrals))
if self._ldap_uri.startswith('ldaps://'):
# Require server certificate but ignore it's validity. (allow self-signed)
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
if self._use_tls:
# Require TLS connection.
ldap.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
# Require server certificate but ignore it's validity. (allow self-signed)
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
connection.start_tls_s()
LOG.debug('Connection now using TLS')
return connection
except ldap.LDAPError as e:
LOG.debug('(_ldap_connect) LDAP Error: %s : Type %s' % (str(e), type(e)))
return False
示例2: __enter__
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [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
示例3: init_app
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def init_app(self, app):
'''
Configures an application. This registers an `after_request` call, and
attaches this `LoginManager` to it as `app.ldap_login_manager`.
'''
self._config = app.config.get('LDAP', {})
app.ldap_login_manager = self
self.config.setdefault('BIND_DN', '')
self.config.setdefault('BIND_AUTH', '')
self.config.setdefault('URI', 'ldap://127.0.0.1')
self.config.setdefault('OPTIONS', {})
# Referrals are disabled by default
self.config['OPTIONS'].setdefault(ldap.OPT_REFERRALS, ldap.OPT_OFF)
if self.config.get('USER_SEARCH') and not isinstance(self.config['USER_SEARCH'], list):
self.config['USER_SEARCH'] = [self.config['USER_SEARCH']]
示例4: authenticate_with_ldap
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def authenticate_with_ldap(self, username, password):
ldap_conn = ldap.initialize(current_app.config.get('LDAP_SERVER'))
ldap_conn.protocol_version = 3
ldap_conn.set_option(ldap.OPT_REFERRALS, 0)
if '@' in username:
who = '{0}@{1}'.format(username.split('@')[0], current_app.config.get('LDAP_DOMAIN'))
else:
who = '{0}@{1}'.format(username, current_app.config.get('LDAP_DOMAIN'))
username = username.split('@')[0]
user = self.get_by_username(username)
try:
if not password:
raise ldap.INVALID_CREDENTIALS
ldap_conn.simple_bind_s(who, password)
if not user:
from api.lib.perm.acl.user import UserCRUD
user = UserCRUD.add(username=username, email=who)
return user, True
except ldap.INVALID_CREDENTIALS:
return user, False
示例5: _get_conn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [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
示例6: __enter__
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def __enter__(self):
import ldap
import ldap.sasl
# TODO: Implement simple bind
if not os.path.exists(config.LDAP_GSSAPI_CRED_CACHE):
raise ValueError("Ticket cache at %s not initialized, unable to "
"authenticate with computer account against LDAP server!" % config.LDAP_GSSAPI_CRED_CACHE)
os.environ["KRB5CCNAME"] = config.LDAP_GSSAPI_CRED_CACHE
self.conn = ldap.initialize(config.LDAP_ACCOUNTS_URI, bytes_mode=False)
self.conn.set_option(ldap.OPT_REFERRALS, 0)
click.echo("Connecing to %s using Kerberos ticket cache from %s" %
(config.LDAP_ACCOUNTS_URI, config.LDAP_GSSAPI_CRED_CACHE))
self.conn.sasl_interactive_bind_s('', ldap.sasl.gssapi())
return self.conn
示例7: test_options
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def test_options(self):
self._init_settings(
USER_DN_TEMPLATE="uid=%(user)s,ou=people,o=test",
CONNECTION_OPTIONS={ldap.OPT_REFERRALS: 0},
)
user = authenticate(username="alice", password="password")
self.assertEqual(user.ldap_user.connection.get_option(ldap.OPT_REFERRALS), 0)
示例8: connect
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def connect(self):
conn = super(ADLDAPAuth, self).connect()
conn.set_option(ldap.OPT_REFERRALS, 0)
conn.protocol_version = 3
return conn
示例9: _ldap_get_con
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def _ldap_get_con():
if not _check_ldap_settings_present():
return None
con = ldap.initialize(fame_config.ldap_uri)
con.protocol_version = ldap.VERSION3
con.set_option(ldap.OPT_REFERRALS, 0)
return con
示例10: ldap_conn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def ldap_conn(ldap_server):
connect = ldap.initialize(ldap_server)
connect.set_option(ldap.OPT_REFERRALS, 0)
return connect
示例11: initializeConnection
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def initializeConnection(self):
if not self.dc_ip:
self.dc_ip = self.getDC_IP(self.domain)
con = ldap.initialize('ldap://{}'.format(self.dc_ip))
con.set_option(ldap.OPT_REFERRALS, 0)
return con
示例12: initializeConnection
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def initializeConnection(self):
if not self.dc_ip:
self.get_set_DC_IP(self.domain)
con = ldap.initialize('ldap://{}'.format(self.dc_ip))
con.set_option(ldap.OPT_REFERRALS, 0)
return con
示例13: ldap_auth
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def ldap_auth(self, username, password):
if self.cert_path:
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self.cert_path)
connection = ldap.initialize(self.ldap_url)
connection.set_option(ldap.OPT_REFERRALS, 0)
if not password:
return False
auth_user = username + self.user_suffix
try:
if self.bind_user:
# use search filter to find DN of username
connection.simple_bind_s(self.bind_user, self.bind_password)
sfilter = self.search_filter % username
result = connection.search_s(self.base_dn, ldap.SCOPE_SUBTREE, sfilter, ['dn'])
if len(result) < 1:
return False
auth_user = result[0][0]
connection.simple_bind_s(auth_user, password)
except ldap.INVALID_CREDENTIALS:
return False
except (ldap.SERVER_DOWN, ldap.INVALID_DN_SYNTAX) as err:
logger.warning("%s", err)
return None
return True
示例14: ldap_auth
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def ldap_auth(self, username, password):
if self.cert_path:
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self.cert_path)
connection = ldap.initialize(self.ldap_url)
connection.set_option(ldap.OPT_REFERRALS, 0)
if not password:
return False
auth_user = username + self.user_suffix
try:
if self.bind_user:
# use search filter to find DN of username
connection.simple_bind_s(self.bind_user, self.bind_password)
sfilter = self.search_filter % username
result = connection.search_s(self.base_dn, ldap.SCOPE_SUBTREE, sfilter, ['dn'])
if len(result) < 1:
return False
auth_user = result[0][0]
connection.simple_bind_s(auth_user, password)
except ldap.INVALID_CREDENTIALS:
return False
except (ldap.SERVER_DOWN, ldap.INVALID_DN_SYNTAX) as err:
logger.warn("%s", err)
return None
return True
示例15: ldap_init_conn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import OPT_REFERRALS [as 别名]
def ldap_init_conn(self):
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
conn = ldap.initialize(Setting().get('ldap_uri'))
conn.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
conn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
conn.set_option(ldap.OPT_X_TLS_DEMAND, True)
conn.set_option(ldap.OPT_DEBUG_LEVEL, 255)
conn.protocol_version = ldap.VERSION3
return conn