Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.BadCredentialsException


            auditManager.audit(Category.authentication, AuthenticationSubCategory.login, Result.failure,
                    "User " + authentication.getPrincipal() + " not authenticated");

            LOG.debug("User {} not authenticated", authentication.getPrincipal());

            throw new BadCredentialsException("User " + authentication.getPrincipal() + " not authenticated");
        }

        return token;
    }
View Full Code Here


    String username = obtainUsername(request).trim();
    String password = obtainPassword(request).trim();
    // System.out.println(">>>>>>>>>>000<<<<<<<<<< username is " +
    // username);
    if (Common.isEmpty(username) || Common.isEmpty(password)) {
      BadCredentialsException exception = new BadCredentialsException(
          "用户名或密码不能为空!");// 在界面输出自定义的信息!!
      throw exception;
    }

    // 验证用户账号与密码是否正确
    User users = this.userDao.querySingleUser(username);
    if (users == null || !users.getUserPassword().equals(password)) {
      BadCredentialsException exception = new BadCredentialsException(
          "用户名或密码不匹配!");// 在界面输出自定义的信息!!
      // request.setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION,
      // exception);
      throw exception;
    }
View Full Code Here

    @Test
    public void onAuthenticationFailure() throws IOException, ServletException {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        AuthenticationException ex = new BadCredentialsException("");

        failureHandler.onAuthenticationFailure(request, response, ex);

        assertEquals(MockHttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
        assertEquals(RestAuthenticationFailureHandler.STATUS_MESSAGE_AUTHENTICATION_FAILED, response.getErrorMessage());
View Full Code Here

    if (auth.getName().equals(auth.getCredentials())) {
      return new UsernamePasswordAuthenticationToken(auth.getName(),
        auth.getCredentials(), AUTHORITIES);
    }
   
    throw new BadCredentialsException("Bad Credentials");
   
  }
View Full Code Here

       
            user = pudsim.loadUserByUsername(principal);
           
        } catch(UsernameNotFoundException ex) {
           
             throw new BadCredentialsException(
                 principal + " principal not found", ex);
           
        }
       
        // Returned user is never null
        if ( !user.isEnabled() ) {
            throw new DisabledException("Username: " + user.getUsername());
        }
       
        if ( !user.isAccountNonLocked() ) {
            throw new LockedException("Username: " + user.getUsername());
        }
       
        if ( !user.getPassword().equals(password) ) {
            throw new BadCredentialsException("Username: " + user.getUsername());
        }
       
        return new UsernamePasswordAuthenticationToken(
            user.getUsername(), user.getPassword(), user.getAuthorities());
       
View Full Code Here

            auditManager.audit(Category.authentication, AuthenticationSubCategory.login, Result.failure,
                    "User " + authentication.getPrincipal() + " not authenticated");

            LOG.debug("User {} not authenticated", authentication.getPrincipal());

            throw new BadCredentialsException("User " + authentication.getPrincipal() + " not authenticated");
        }

        return token;
    }
View Full Code Here

                serverDigestMd5 = digestAuth.calculateServerDigest(user.getPassword(), request.getMethod());
            }

        } catch (UsernameNotFoundException notFound) {
            fail(request, response,
                    new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.usernameNotFound",
                            new Object[]{digestAuth.getUsername()}, "Username {0} not found")));

            return;
        }


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

            fail(request, response,
                    new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.incorrectResponse",
                            "Incorrect response")));
            return;
        }

        // To get this far, the digest must have been valid
View Full Code Here

        }

        void validateAndDecode(String entryPointKey, String expectedRealm) throws BadCredentialsException {
            // Check all required parameters were supplied (ie RFC 2069)
            if ((username == null) || (realm == null) || (nonce == null) || (uri == null) || (response == null)) {
                throw new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.missingMandatory",
                            new Object[]{section212response}, "Missing mandatory digest value; received header {0}"));
            }
            // 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 + "'");
                    }

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

            // Check realm name equals what we expected
            if (!expectedRealm.equals(realm)) {
                throw new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.incorrectRealm",
                            new Object[]{realm, expectedRealm},
                            "Response realm name '{0}' does not match system realm name of '{1}'"));
            }

            // Check nonce was Base64 encoded (as sent by DigestAuthenticationEntryPoint)
            if (!Base64.isBase64(nonce.getBytes())) {
                throw new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.nonceEncoding",
                           new Object[]{nonce}, "Nonce is not encoded in Base64; received nonce {0}"));
            }

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

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

            // Extract expiry time from nonce

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

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

            if (!expectedNonceSignature.equals(nonceTokens[1])) {
                new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.nonceCompromised",
                                new Object[]{nonceAsPlainText}, "Nonce token compromised {0}"));
            }
        }
View Full Code Here

                User user = myUserRepository.findByUsername(username);
                if(user == null) {
                    throw new UsernameNotFoundException("No user for principal "+principal);
                }
                if(!authentication.getCredentials().equals(user.getPassword())) {
                    throw new BadCredentialsException("Invalid password");
                }
                return new TestingAuthenticationToken(principal, null, "ROLE_USER");
            }
        };
    }
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

TOP

Related Classes of org.springframework.security.authentication.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.