当前位置: 首页>>代码示例>>Python>>正文


Python ldap.OPT_REFERRALS属性代码示例

本文整理汇总了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 
开发者ID:StackStorm,项目名称:st2-auth-backend-ldap,代码行数:27,代码来源:ldap_backend.py

示例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 
开发者ID:quay,项目名称:quay,代码行数:18,代码来源:externalldap.py

示例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']] 
开发者ID:ContinuumIO,项目名称:flask-ldap-login,代码行数:20,代码来源:__init__.py

示例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 
开发者ID:pycook,项目名称:cmdb,代码行数:27,代码来源:acl.py

示例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 
开发者ID:peterpakos,项目名称:checkipaconsistency,代码行数:25,代码来源:freeipaserver.py

示例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 
开发者ID:laurivosandi,项目名称:certidude,代码行数:17,代码来源:user.py

示例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) 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:10,代码来源:tests.py

示例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 
开发者ID:Net-ng,项目名称:kansha,代码行数:7,代码来源:ldap_auth.py

示例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 
开发者ID:certsocietegenerale,项目名称:fame,代码行数:10,代码来源:user_management.py

示例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 
开发者ID:SAP,项目名称:InfraBox,代码行数:7,代码来源:account_ldap.py

示例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 
开发者ID:ropnop,项目名称:windapsearch,代码行数:9,代码来源:windapsearch_py2.py

示例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 
开发者ID:ropnop,项目名称:windapsearch,代码行数:9,代码来源:windapsearch.py

示例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 
开发者ID:linkedin,项目名称:iris,代码行数:30,代码来源:ldap.py

示例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 
开发者ID:linkedin,项目名称:oncall,代码行数:31,代码来源:ldap_example.py

示例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 
开发者ID:ngoduykhanh,项目名称:PowerDNS-Admin,代码行数:12,代码来源:user.py


注:本文中的ldap.OPT_REFERRALS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。