當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。