Package org.springframework.security.core

Examples of org.springframework.security.core.AuthenticationException


    @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


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

        authenticationEntryPoint.commence(request, response, ex);

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

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

            if(session != null) {
                AuthenticationException ex = (AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
                errorMsg = ex != null ? ex.getMessage() : "none";
            }
        }

        StringBuilder sb = new StringBuilder();
View Full Code Here

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

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

        }
    }

    @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

        SimpleUrlAuthenticationFailureHandler afh = new SimpleUrlAuthenticationFailureHandler();
        afh.setDefaultFailureUrl("/target");
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();

        AuthenticationException e = mock(AuthenticationException.class);

        afh.onAuthenticationFailure(request, response, e);
        assertSame(e, request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION));
        assertEquals("/target", response.getRedirectedUrl());
    }
View Full Code Here

        afh.setUseForward(true);
        assertTrue(afh.isUseForward());

        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        AuthenticationException e = mock(AuthenticationException.class);

        afh.onAuthenticationFailure(request, response, e);
        assertNull(request.getSession(false));
        assertNull(response.getRedirectedUrl());
        assertEquals("/target", response.getForwardedUrl());
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

        p.put(MockAuthenticationException.class.getName(), AuthenticationFailureDisabledEvent.class.getName());
        publisher.setAdditionalExceptionMappings(p);
        ApplicationEventPublisher appPublisher = mock(ApplicationEventPublisher.class);

        publisher.setApplicationEventPublisher(appPublisher);
        publisher.publishAuthenticationFailure(new AuthenticationException("") {}, mock(Authentication.class));
        verifyZeroInteractions(appPublisher);
    }
View Full Code Here

    }

    @Test
    public void publishNullPublisher() {
        provider.setApplicationEventPublisher(null);
        AuthenticationException ae = new BadCredentialsException("Failed to login", token);

        provider.publishFailureEvent(token, ae);
        provider.publishSuccessEvent(token);
    }
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.