Package org.springframework.security.core

Examples of org.springframework.security.core.AuthenticationException


        assertEquals(auth, event.getAuthentication());
    }

    public void testAbstractAuthenticationFailureEvent() {
        Authentication auth = getAuthentication();
        AuthenticationException exception = new DisabledException("TEST");
        AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(auth, exception);
        assertEquals(auth, event.getAuthentication());
        assertEquals(exception, event.getException());
    }
View Full Code Here


        assertEquals(auth, event.getAuthentication());
        assertEquals(exception, event.getException());
    }

    public void testRejectsNullAuthentication() {
        AuthenticationException exception = new DisabledException("TEST");

        try {
            new AuthenticationFailureDisabledEvent(null, exception);
            fail("Should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
View Full Code Here

    @Test
    public void testCommence() throws IOException, ServletException {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        AuthenticationException exception = new BadCredentialsException("Bad Credential");

        restAuthenticationEntryPoint.commence(request, response, exception);

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

            SecurityContextHolder.getContext().setAuthentication(null);
            DummyFilterChain dummyFilter = new DummyFilterChain();
            filter.doFilter(request, response, dummyFilter);
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            if (auth == null) {
                AuthenticationException ex = new AuthenticationCredentialsNotFoundException("Anonymous access denied");
                authenticationEntryPoint.commence(request, response, ex);
                return false;
            }
            return dummyFilter.isCalled();
        } catch (ServletException e) {
View Full Code Here

        if (loginError) {
            HttpSession session = request.getSession(false);

            if(session != null) {
                lastUser = (String) session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY);
                AuthenticationException ex = (AuthenticationException) session.getAttribute(AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY);
                errorMsg = ex != null ? ex.getMessage() : "none";
                if (lastUser == null) {
                    lastUser = "";
                }
            }
        }
View Full Code Here

            //we're done, return the token.
            return result;

        } catch (LoginException loginException) {
            AuthenticationException ase = loginExceptionResolver.resolveException(loginException);

            publishFailureEvent(request, ase);
            throw ase;
        }
    }
View Full Code Here

     *
     * @throws AuthenticationException if authentication fails.
     */
    public Authentication doAuthentication(Authentication authentication) throws AuthenticationException {
        Class<? extends Authentication> toTest = authentication.getClass();
        AuthenticationException lastException = null;
        Authentication result = null;

        for (AuthenticationProvider provider : getProviders()) {
            if (!provider.supports(toTest)) {
                continue;
View Full Code Here

    @Test
    public void testOnAuthenticationFailureShouldRedirectToLoginPage() throws Exception {
        JCUser user = new JCUser("username", "email", "password");
        Authentication auth = new TestingAuthenticationToken(user, null);

        AuthenticationException exception = new BadCredentialsException("Password doesn't match!");
        exception.setAuthentication(auth);

        RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
        handler.setRedirectStrategy(redirectStrategy);
        handler.setDefaultFailureUrl("/badlogin?login_error=1");
        handler.setUsernameSessionAttribute("j_user_name");
View Full Code Here

     *
     * @throws AuthenticationException if authentication fails.
     */
    public Authentication doAuthentication(Authentication authentication) throws AuthenticationException {
        Class<? extends Authentication> toTest = authentication.getClass();
        AuthenticationException lastException = null;
        Authentication result = null;

        for (AuthenticationProvider provider : getProviders()) {
            if (!provider.supports(toTest)) {
                continue;
View Full Code Here

        if (loginError) {
            HttpSession session = request.getSession(false);

            if(session != null) {
                lastUser = (String) session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY);
                AuthenticationException ex = (AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
                errorMsg = ex != null ? ex.getMessage() : "none";
                if (lastUser == null) {
                    lastUser = "";
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.AuthenticationException

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.