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


Python ldap.set_option方法代码示例

本文整理汇总了Python中ldap.set_option方法的典型用法代码示例。如果您正苦于以下问题:Python ldap.set_option方法的具体用法?Python ldap.set_option怎么用?Python ldap.set_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ldap的用法示例。


在下文中一共展示了ldap.set_option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _connect_to_ldap

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [as 别名]
def _connect_to_ldap(self):
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
        connection = ldap.initialize(self.server_uri)

        if self.start_tls:
            try:
                connection.start_tls_s()
            except ldap.LDAPError:
                e = get_exception()
                self.module.fail_json(msg="Cannot start TLS.", details=str(e))

        try:
            if self.bind_dn is not None:
                connection.simple_bind_s(self.bind_dn, self.bind_pw)
            else:
                connection.sasl_interactive_bind_s('', ldap.sasl.external())
        except ldap.LDAPError:
            e = get_exception()
            self.module.fail_json(
                msg="Cannot bind to the server.", details=str(e))

        return connection 
开发者ID:IBM-Security,项目名称:isam-ansible-roles,代码行数:24,代码来源:ldap_attr.py

示例2: _ldap_connect

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例3: initialize

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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)) 
开发者ID:alexferl,项目名称:flask-simpleldap,代码行数:22,代码来源:__init__.py

示例4: _get_conn

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例5: get_ldap

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [as 别名]
def get_ldap(cls, global_options=None):
        """
        Returns the configured ldap module.
        """
        # Apply global LDAP options once
        if not cls._ldap_configured and global_options is not None:
            for opt, value in global_options.items():
                ldap.set_option(opt, value)

            cls._ldap_configured = True

        return ldap 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:14,代码来源:config.py

示例6: _ldap_get_con

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例7: get_connection

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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 
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:32,代码来源:ldap_factory.py

示例8: ldap_conn

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例9: get_ldap_connection

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [as 别名]
def get_ldap_connection(host):
    conn = ldap.initialize("ldap://{}".format(host))
    conn.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3)
    conn.start_tls_s()
    return conn 
开发者ID:zentralopensource,项目名称:zentral,代码行数:7,代码来源:__init__.py

示例10: ldap_auth

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例11: ldap_auth

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例12: ldap_init_conn

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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

示例13: initialise

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [as 别名]
def initialise():
    ldap.set_option(ldap.OPT_DEBUG_LEVEL, toolkit.config[u'ckanext.ldap.debug_level']) 
开发者ID:NaturalHistoryMuseum,项目名称:ckanext-ldap,代码行数:4,代码来源:login.py

示例14: init_ldap

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [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 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:28,代码来源:ldap_auth.py

示例15: _set_custom_options

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import set_option [as 别名]
def _set_custom_options(conn):
        options = current_app.config['LDAP_CUSTOM_OPTIONS']
        if options:
            for k, v in options.items():
                conn.set_option(k, v)
        return conn 
开发者ID:alexferl,项目名称:flask-simpleldap,代码行数:8,代码来源:__init__.py


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