Package org.acegisecurity

Examples of org.acegisecurity.BadCredentialsException


            try {
                user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);
            } catch (UsernameNotFoundException notFound) {
                if (hideUserNotFoundExceptions) {
                    throw new BadCredentialsException(messages.getMessage(
                            "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
                } else {
                    throw notFound;
                }
            }
View Full Code Here


        // If an existing CasAuthenticationToken, just check we created it
        if (authentication instanceof CasAuthenticationToken) {
            if (this.key.hashCode() == ((CasAuthenticationToken) authentication).getKeyHash()) {
                return authentication;
            } else {
                throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.incorrectKey",
                        "The presented CasAuthenticationToken does not contain the expected key"));
            }
        }

        // Ensure credentials are presented
        if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
            throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket",
                    "Failed to provide a CAS service ticket to validate"));
        }

        boolean stateless = false;
View Full Code Here

    if (this.saltSource != null) {
      salt = this.saltSource.getSalt(userDetails);
    }

    if (authentication.getCredentials() == null) {
      throw new BadCredentialsException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"),
          includeDetailsObject ? userDetails : null);
    }

    String presentedPassword = authentication.getCredentials() == null ? "" : authentication.getCredentials()
        .toString();

    if (!passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword, salt)) {
      throw new BadCredentialsException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"),
          includeDetailsObject ? userDetails : null);
    }
  }
View Full Code Here

        } catch (Exception internalProxyTicketValidatorProblem) {
            throw new AuthenticationServiceException(internalProxyTicketValidatorProblem.getMessage());
        }

        if (!pv.isAuthenticationSuccesful()) {
            throw new BadCredentialsException(pv.getErrorCode() + ": " + pv.getErrorMessage());
        }

        return new TicketResponse(pv.getUser(), pv.getProxyList(), pv.getPgtIou());
    }
View Full Code Here

        X509Certificate clientCertificate = (X509Certificate) authentication
            .getCredentials();

        if (clientCertificate == null) {
            throw new BadCredentialsException(messages.getMessage(
                    "X509AuthenticationProvider.certificateNull",
                    "Certificate is null"));
        }

        UserDetails user = userCache.getUserFromCache(clientCertificate);
View Full Code Here

        } catch(CommunicationException ce) {
            throw new LdapDataAccessException(messages.getMessage(
                            "DefaultIntitalDirContextFactory.communicationFailure",
                            "Unable to connect to LDAP server"), ce);
        } catch(javax.naming.AuthenticationException ae) {
            throw new BadCredentialsException(messages.getMessage(
                            "DefaultIntitalDirContextFactory.badCredentials",
                            "Bad credentials"), ae);
        } catch (NamingException nx) {
            throw new LdapDataAccessException(messages.getMessage(
                            "DefaultIntitalDirContextFactory.unexpectedException",
View Full Code Here

        throws AuthenticationException {
        String subjectDN = clientCert.getSubjectDN().getName();
        PatternMatcher matcher = new Perl5Matcher();

        if (!matcher.contains(subjectDN, subjectDNPattern)) {
            throw new BadCredentialsException(messages.getMessage(
                    "DaoX509AuthoritiesPopulator.noMatching",
                    new Object[] {subjectDN},
                    "No matching pattern was found in subjectDN: {0}"));
        }
View Full Code Here

                        + "'; uri: '" + username + "'; response: '" + username
                        + "'");
                }

                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.missingMandatory",
                            new Object[] {section212response},
                            "Missing mandatory digest value; received header {0}")));

                return;
            }

            // Check all required parameters for an "auth" qop were supplied (ie RFC 2617)
            if ("auth".equals(qop)) {
                if ((nc == null) || (cnonce == null)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("extracted nc: '" + nc + "'; cnonce: '"
                            + cnonce + "'");
                    }

                    fail(request, response,
                        new BadCredentialsException(messages.getMessage(
                                "DigestProcessingFilter.missingAuth",
                                new Object[] {section212response},
                                "Missing mandatory digest value; received header {0}")));

                    return;
                }
            }

            // Check realm name equals what we expected
            if (!this.getAuthenticationEntryPoint().getRealmName().equals(realm)) {
                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.incorrectRealm",
                            new Object[] {realm, this.getAuthenticationEntryPoint()
                                                     .getRealmName()},
                            "Response realm name '{0}' does not match system realm name of '{1}'")));

                return;
            }

            // Check nonce was a Base64 encoded (as sent by DigestProcessingFilterEntryPoint)
            if (!Base64.isArrayByteBase64(nonce.getBytes())) {
                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.nonceEncoding",
                            new Object[] {nonce},
                            "Nonce is not encoded in Base64; received nonce {0}")));

                return;
            }

            // Decode nonce from Base64
            // format of nonce is: 
            //   base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
            String nonceAsPlainText = new String(Base64.decodeBase64(
                        nonce.getBytes()));
            String[] nonceTokens = StringUtils.delimitedListToStringArray(nonceAsPlainText,
                    ":");

            if (nonceTokens.length != 2) {
                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.nonceNotTwoTokens",
                            new Object[] {nonceAsPlainText},
                            "Nonce should have yielded two tokens but was {0}")));

                return;
            }

            // Extract expiry time from nonce
            long nonceExpiryTime;

            try {
                nonceExpiryTime = new Long(nonceTokens[0]).longValue();
            } catch (NumberFormatException nfe) {
                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.nonceNotNumeric",
                            new Object[] {nonceAsPlainText},
                            "Nonce token should have yielded a numeric first token, but was {0}")));

                return;
            }

            // Check signature of nonce matches this expiry time
            String expectedNonceSignature = DigestUtils.md5Hex(nonceExpiryTime
                    + ":" + this.getAuthenticationEntryPoint().getKey());

            if (!expectedNonceSignature.equals(nonceTokens[1])) {
                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.nonceCompromised",
                            new Object[] {nonceAsPlainText},
                            "Nonce token compromised {0}")));

                return;
            }

            // Lookup password for presented username
            // NB: DAO-provided password MUST be clear text - not encoded/salted
            // (unless this instance's passwordAlreadyEncoded property is 'false')
            boolean loadedFromDao = false;
            UserDetails user = userCache.getUserFromCache(username);

            if (user == null) {
                loadedFromDao = true;

                try {
                    user = userDetailsService.loadUserByUsername(username);
                } catch (UsernameNotFoundException notFound) {
                    fail(request, response,
                        new BadCredentialsException(messages.getMessage(
                                "DigestProcessingFilter.usernameNotFound",
                                new Object[] {username},
                                "Username {0} not found")));

                    return;
                }

                if (user == null) {
                    throw new AuthenticationServiceException(
                        "AuthenticationDao returned null, which is an interface contract violation");
                }

                userCache.putUserInCache(user);
            }

            // Compute the expected response-digest (will be in hex form)
            String serverDigestMd5;

            // Don't catch IllegalArgumentException (already checked validity)
            serverDigestMd5 = generateDigest(passwordAlreadyEncoded, username,
                    realm, user.getPassword(),
                    ((HttpServletRequest) request).getMethod(), uri, qop,
                    nonce, nc, cnonce);

            // If digest is incorrect, try refreshing from backend and recomputing
            if (!serverDigestMd5.equals(responseDigest) && !loadedFromDao) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                        "Digest comparison failure; trying to refresh user from DAO in case password had changed");
                }

                try {
                    user = userDetailsService.loadUserByUsername(username);
                } catch (UsernameNotFoundException notFound) {
                    // Would very rarely happen, as user existed earlier
                    fail(request, response,
                        new BadCredentialsException(messages.getMessage(
                                "DigestProcessingFilter.usernameNotFound",
                                new Object[] {username},
                                "Username {0} not found")));
                }

                userCache.putUserInCache(user);

                // Don't catch IllegalArgumentException (already checked validity)
                serverDigestMd5 = generateDigest(passwordAlreadyEncoded,
                        username, realm, user.getPassword(),
                        ((HttpServletRequest) request).getMethod(), uri, qop,
                        nonce, nc, cnonce);
            }

            // If digest is still incorrect, definitely reject authentication attempt
            if (!serverDigestMd5.equals(responseDigest)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Expected response: '" + serverDigestMd5
                        + "' but received: '" + responseDigest
                        + "'; is AuthenticationDao returning clear text passwords?");
                }

                fail(request, response,
                    new BadCredentialsException(messages.getMessage(
                            "DigestProcessingFilter.incorrectResponse",
                            "Incorrect response")));

                return;
            }
View Full Code Here

                    // Assume it's binary
                    retrievedPassword = new String((byte[])retrievedPassword);
                }

                if (!verifyPassword(password, (String)retrievedPassword)) {
                    throw new BadCredentialsException(messages.getMessage(
                            "PasswordComparisonAuthenticator.badCredentials",
                            "Bad credentials"));
                }

            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Password attribute " + passwordAttributeName
                            + " wasn't retrieved for user " + username);
                }

                doPasswordCompare(ctx, user.getRelativeName(ctx), password);
            }

            return user;
        } catch(NamingException ne) {
            throw new BadCredentialsException("Authentication failed due to exception ", ne);
        } finally {
            LdapUtils.closeContext(ctx);
        }
    }
View Full Code Here

        NamingEnumeration results = ctx.search(name, passwordCompareFilter,
                new Object[]{passwordBytes}, ctls);

        if(!results.hasMore()) {
            throw new BadCredentialsException(messages.getMessage(
                            "PasswordComparisonAuthenticator.badCredentials",
                            "Bad credentials"));
        }
    }
View Full Code Here

TOP

Related Classes of org.acegisecurity.BadCredentialsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.