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


Python ldap.INVALID_CREDENTIALS属性代码示例

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


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

示例1: _check_ldap_password

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def _check_ldap_password(cn, password):
    """Checks that the given cn/password credentials work on the given CN.

    @param cn: Common name to log on
    @param password: Password for cn
    @return: True on success, False on failure
    """
    cnx = ldap.initialize(config['ckanext.ldap.uri'])
    try:
        cnx.bind_s(cn, password)
    except ldap.SERVER_DOWN:
        log.error('LDAP server is not reachable')
        return False
    except ldap.INVALID_CREDENTIALS:
        log.debug('Invalid LDAP credentials')
        return False
    # Fail on empty password
    if password == '':
        log.debug('Invalid LDAP credentials')
        return False
    cnx.unbind_s()
    return True 
开发者ID:italia,项目名称:daf-recipes,代码行数:24,代码来源:user.py

示例2: check_password

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def check_password(self, uid, password):
        """Check if the specified couple user/password is correct

        In:
           - ``uid`` -- the user id
           - ``password`` -- the user password
        Return:
            - True if password is checked
        """
        c = self.connect()
        dn = self.get_user_dn(uid)
        # Try to authenticate
        try:
            c.simple_bind_s(dn, password.encode('UTF-8'))
            return True
        except ldap.INVALID_CREDENTIALS:
            log.info("Bad credentials for DN %r" % dn)
        except ldap.SERVER_DOWN:
            log.critical("LDAP server down")
        finally:
            c.unbind() 
开发者ID:Net-ng,项目名称:kansha,代码行数:23,代码来源:ldap_auth.py

示例3: login

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def login(self, request, auth_api):
        post_data = request.POST
        try:
            user_id = post_data.getone('user_id')
            org_id = post_data.getone('org_id')
            password = post_data.getone('password')
        except KeyError as e:
            LOGGER.debug('User has not filled all credential fields for authentication. %s.',
                         e.message)
            raise HTTPForbidden
        if user_id and org_id and password:
            try:
                auth_api.authenticate_with_password(org_id, user_id, password)
            except INVALID_CREDENTIALS:
                LOGGER.warning('User tried to authenticate with invalid credentials. '
                               'User id: %r, organization id: %r.', user_id, org_id)
                raise HTTPForbidden
            credentials = self._join_org_id_user_id(org_id, user_id)
            headers = remember(request, credentials)
            self._add_content_type_header(headers)
            return Response(headerlist=headers) 
开发者ID:CERT-Polska,项目名称:n6,代码行数:23,代码来源:data_backend_api.py

示例4: login

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        try:
            user = authenticate(request.form.get('email'), request.form.get('password'))
        except SERVER_DOWN:
            flash("LDAP Server down.", "danger")
            return render_template('login.html')
        except INVALID_CREDENTIALS:
            flash("Invalid credentials.", "danger")
            return render_template('login.html')
        except LdapSettingsNotPresentException:
            flash("LDAP Settings not present. Check server logs.", "danger")
            return render_template('login.html')

        if not user or not user_has_groups_and_sharing(user):
            flash("Access not allowed.", "danger")
            return render_template('login.html')

        redir = request.args.get('next', '/')
        return redirect(redir) 
开发者ID:certsocietegenerale,项目名称:fame,代码行数:24,代码来源:views.py

示例5: ldap_authenticate

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def ldap_authenticate(email, password):
    con = _ldap_get_con()
    if not con:
        raise LdapSettingsNotPresentException

    ldap_user = _find_user_by_email(con, email)

    if ldap_user:
        try:
            con.simple_bind_s(ldap_user['principal'], password)
            return ldap_user
        except ldap.INVALID_CREDENTIALS:
            # forward exception to view
            raise
        finally:
            con.unbind_s() 
开发者ID:certsocietegenerale,项目名称:fame,代码行数:18,代码来源:user_management.py

示例6: _check_password

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def _check_password(self, password):
        """Check the given password against the stored password for the user."""
        # If either username or password are empty strings or None, reject user.
        if not self.get_username() or not password:
            return False

        try:
            self.po__get_registered_object('ldap_factory').get_connection(bind_dn=self._get_dn(),
                                                                       password=password)
            return True
        except ldap.INVALID_CREDENTIALS:
            pass
        except MCVirtException:
            raise
        except Exception:
            raise LdapConnectionFailedException('An error occurred whilst connecting to LDAP')
        return False 
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:19,代码来源:ldap_user.py

示例7: main

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def main():
	try:
		# Open a connection
		ldap_client = ldap.initialize(LDAP_SERVER)
		# Set LDAPv3 option
		ldap_client.set_option(ldap.OPT_PROTOCOL_VERSION,3)
		# Bind/authenticate with a user with appropriate rights
		ldap_client.simple_bind("admin",'Secret123')
		# Get user attributes defined in LDAP_ATTRS
		result = ldap_client.search_s(LDAP_BASE_DN,ldap.SCOPE_SUBTREE,LDAP_FILTER, LDAP_ATTRS)
		print(result)
	except ldap.INVALID_CREDENTIALS as exception:
		ldap_client.unbind()
		print('Wrong username or password. '+exception)
	except ldap.SERVER_DOWN as exception:
		print('LDAP server not available. '+exception) 
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:18,代码来源:connect_python_ldap.py

示例8: direct_bind

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def direct_bind(self, username, password):
        """
        Bind to username/password directly
        """
        log.debug("Performing direct bind")

        ctx = {'username':username, 'password':password}
        scope = self.config.get('SCOPE', ldap.SCOPE_SUBTREE)
        user = self.config['BIND_DN'] % ctx

        try:
            log.debug("Binding with the BIND_DN %s" % user)
            self.conn.simple_bind_s(user, password)
        except ldap.INVALID_CREDENTIALS:
            if self._raise_errors:
                raise ldap.INVALID_CREDENTIALS("Unable to do a direct bind with BIND_DN %s" % user)
            return None
        results = self.conn.search_s(user, scope, attrlist=self.attrlist)
        self.conn.unbind_s()
        return self.format_results(results) 
开发者ID:ContinuumIO,项目名称:flask-ldap-login,代码行数:22,代码来源:__init__.py

示例9: validate_ldap

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def validate_ldap(self):
        'Validate the username/password data against ldap directory'
        ldap_mgr = current_app.ldap_login_manager
        username = self.username.data
        password = self.password.data
        try:
            userdata = ldap_mgr.ldap_login(username, password)
        except ldap.INVALID_CREDENTIALS:
            flash("Invalid LDAP credentials", 'danger')
            return False
        except ldap.LDAPError as err:
            if isinstance(err.message, dict):
                message = err.message.get('desc', str(err))
            else:
                message = str(err.message)
            flash(message, 'danger')
            return False

        if userdata is None:
            flash("Invalid LDAP credentials", 'danger')
            return False

        self.user = ldap_mgr._save_user(username, userdata)
        return True 
开发者ID:ContinuumIO,项目名称:flask-ldap-login,代码行数:26,代码来源:forms.py

示例10: verify_passwd

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def verify_passwd(self, passwd):
        """
        Validate the provided password against the hash stored in LDAP.

        :param str passwd: password to check
        """
        try:
            c = ldap.initialize("ldap://localhost")
            c.simple_bind_s(self.ldap_id, passwd)
            data = c.search_s("cn=admins,ou=groups," + self.rootdn,
                              ldap.SCOPE_SUBTREE, "(objectClass=*)",
                              ["member"])[0][1]["member"]
            if b(self.ldap_id) not in data:
                return False
            return True
        except ldap.INVALID_CREDENTIALS:
            return False 
开发者ID:arkOScloud,项目名称:core,代码行数:19,代码来源:users.py

示例11: auth

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def auth(self, username, password):

        binddn = username + '@' + self.domain
        if binddn is not None:
            ldap_client = self._connect()
            try:
                ldap_client.simple_bind_s(
                    self._byte_p2(binddn),
                    self._byte_p2(password)
                )
            except ldap.INVALID_CREDENTIALS:
                ldap_client.unbind_s()
                return False
            ldap_client.unbind_s()
            return True
        else:
            return False 
开发者ID:kakwa,项目名称:ldapcherry,代码行数:19,代码来源:backendAD.py

示例12: auth

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def auth(self, username, password):
        """Authentication of a user"""

        binddn = self._get_user(self._byte_p2(username), NO_ATTR)
        if binddn is not None:
            ldap_client = self._connect()
            try:
                ldap_client.simple_bind_s(
                        self._byte_p2(binddn),
                        self._byte_p2(password)
                        )
            except ldap.INVALID_CREDENTIALS:
                ldap_client.unbind_s()
                return False
            ldap_client.unbind_s()
            return True
        else:
            return False 
开发者ID:kakwa,项目名称:ldapcherry,代码行数:20,代码来源:backendLdap.py

示例13: check_ldap_password

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def check_ldap_password(cn, password):
    '''Checks that the given cn/password credentials work on the given CN.

    :param cn: Common name to log on
    :param password: Password for cn
    :returns: True on success, False on failure

    '''
    cnx = ldap.initialize(toolkit.config[u'ckanext.ldap.uri'], bytes_mode=False,
                          trace_level=toolkit.config[u'ckanext.ldap.trace_level'])
    try:
        cnx.bind_s(cn, password)
    except ldap.SERVER_DOWN:
        log.error(u'LDAP server is not reachable')
        return False
    except ldap.INVALID_CREDENTIALS:
        log.debug(u'Invalid LDAP credentials')
        return False
    # Fail on empty password
    if password == u'':
        log.debug(u'Invalid LDAP credentials')
        return False
    cnx.unbind_s()
    return True 
开发者ID:NaturalHistoryMuseum,项目名称:ckanext-ldap,代码行数:26,代码来源:_helpers.py

示例14: set_password

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import INVALID_CREDENTIALS [as 别名]
def set_password(self, user, old_password, new_password):
        dn = ldap_user_dn(user.username)
        if old_password:
            ldap_ident = dn
            ldap_pass = old_password.encode('utf-8')
        else:
            ldap_ident = ldap_pass = None
        try:
            con = ldap_conn(ldap_ident, ldap_pass)
            new_password = self._encode_password(new_password)
            con.modify_s(
                dn, [(ldap.MOD_REPLACE, b'userPassword', new_password)])
            con.unbind_s()
            user.last_password_updated = datetime.utcnow()
            session(user).flush(user)
        except ldap.INVALID_CREDENTIALS:
            raise exc.HTTPUnauthorized() 
开发者ID:apache,项目名称:allura,代码行数:19,代码来源:plugin.py

示例15: authenticate_with_ldap

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


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