Examples of BadCredentialsException


Examples of org.springframework.security.authentication.BadCredentialsException

    @Test(expected=AuthenticationException.class)
    public void testNullServiceTicketHandledGracefully() throws Exception {
        CasAuthenticationFilter filter = new CasAuthenticationFilter();
        filter.setAuthenticationManager(new AuthenticationManager() {
            public Authentication authenticate(Authentication a) {
                throw new BadCredentialsException("Rejected");
            }
        });

        filter.attemptAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse());
    }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        logger.debug("Subject DN is '" + subjectDN + "'");

        Matcher matcher = subjectDnPattern.matcher(subjectDN);

        if (!matcher.find()) {
            throw new BadCredentialsException(messages.getMessage("SubjectDnX509PrincipalExtractor.noMatching",
                    new Object[] {subjectDN}, "No matching pattern was found in subject DN: {0}"));
        }

        if (matcher.groupCount() != 1) {
            throw new IllegalArgumentException("Regular expression must contain a single group ");
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

                user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);
            } catch (UsernameNotFoundException notFound) {
                logger.debug("User '" + username + "' not found");

                if (hideUserNotFoundExceptions) {
                    throw new BadCredentialsException(messages.getMessage(
                            "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
                } else {
                    throw notFound;
                }
            }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        }

        if (authentication.getCredentials() == null) {
            logger.debug("Authentication failed: no credentials provided");

            throw new BadCredentialsException(messages.getMessage(
                    "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails);
        }

        String presentedPassword = authentication.getCredentials().toString();

        if (!passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword, salt)) {
            logger.debug("Authentication failed: password does not match stored value");

            throw new BadCredentialsException(messages.getMessage(
                    "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails);
        }
    }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        RunAsUserToken token = (RunAsUserToken) authentication;

        if (token.getKeyHash() == key.hashCode()) {
            return authentication;
        } else {
            throw new BadCredentialsException(messages.getMessage("RunAsImplAuthenticationProvider.incorrectKey",
                    "The presented RunAsUserToken does not contain the expected key"));
        }
    }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

    public void testFailedAuthenticationThrowsException() {
        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
        request.addParameter(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY, "rod");
        UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        filter.setAuthenticationManager(am);

        try {
            filter.attemptAuthentication(request, new MockHttpServletResponse());
            fail("Expected AuthenticationException");
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        }
    }

    @Test
    public void loginFail() throws Exception {
        AuthenticationException authException = new BadCredentialsException("Invalid");
        when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))).thenThrow(authException);

        try {
            wrappedRequest().login("invalid","credentials");
            Assert.fail("Expected Exception");
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

    @Test
    public void defaultTargetUrlIsUsedIfNoMappingExists() throws Exception {
        ExceptionMappingAuthenticationFailureHandler fh = new ExceptionMappingAuthenticationFailureHandler();
        fh.setDefaultFailureUrl("/failed");
        MockHttpServletResponse response = new MockHttpServletResponse();
        fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException(""));

        assertEquals("/failed", response.getRedirectedUrl());
    }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        HashMap<String, String> mapping = new HashMap<String, String>();
        mapping.put("org.springframework.security.authentication.BadCredentialsException", "/badcreds");
        fh.setExceptionMappings(mapping);
        fh.setDefaultFailureUrl("/failed");
        MockHttpServletResponse response = new MockHttpServletResponse();
        fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException(""));

        assertEquals("/badcreds", response.getRedirectedUrl());
    }
View Full Code Here

Examples of org.springframework.security.authentication.BadCredentialsException

        public MockAuthenticationFilter(boolean grantAccess) {
            this();
            setRememberMeServices(new NullRememberMeServices());
            this.grantAccess = grantAccess;
            this.exceptionToThrow = new BadCredentialsException("Mock requested to do so");
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.