Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.AuthenticationManager


        assertNull(request.getSession(false));
    }

    private AuthenticationManager createAuthenticationManager() {
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
            public Authentication answer(InvocationOnMock invocation) throws Throwable {
                return (Authentication) invocation.getArguments()[0];
            }
        });
View Full Code Here


        WebSphere2SpringSecurityPropagationInterceptor interceptor =
            new WebSphere2SpringSecurityPropagationInterceptor(helper);

        final SecurityContext context = new SecurityContextImpl();

        interceptor.setAuthenticationManager(new AuthenticationManager() {
            public Authentication authenticate(Authentication authentication) {
                // Store the auth object
                context.setAuthentication(authentication);
                return null;
            }
View Full Code Here

    /**
     * Create an authentication manager which returns the passed in object.
     */
    private AuthenticationManager createAuthenticationManager() {
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
            public Authentication answer(InvocationOnMock invocation) throws Throwable {
                return (Authentication) invocation.getArguments()[0];
            }
        });

View Full Code Here

    @Test
    public void testOperationWhenNoAuthenticationInContextHolder() throws Exception {

        RememberMeAuthenticationFilter filter = new RememberMeAuthenticationFilter();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(remembered)).thenReturn(remembered);
        filter.setAuthenticationManager(am);
        filter.setRememberMeServices(new MockRememberMeServices(remembered));
        filter.afterPropertiesSet();

        MockHttpServletRequest request = new MockHttpServletRequest();
View Full Code Here

            protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) {
                super.onUnsuccessfulAuthentication(request, response, failed);
                SecurityContextHolder.getContext().setAuthentication(failedAuth);
            }
        };
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        filter.setAuthenticationManager(am);
        filter.setRememberMeServices(new MockRememberMeServices(remembered));
        filter.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
        filter.afterPropertiesSet();
View Full Code Here

    }

    @Test
    public void authenticationSuccessHandlerIsInvokedOnSuccessfulAuthenticationIfSet() throws Exception {
        RememberMeAuthenticationFilter filter = new RememberMeAuthenticationFilter();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(remembered)).thenReturn(remembered);
        filter.setAuthenticationManager(am);
        filter.setRememberMeServices(new MockRememberMeServices(remembered));
        filter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("/target"));
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
View Full Code Here

        when(helper.getCurrentUserName()).thenReturn("jerry");
        WebSpherePreAuthenticatedProcessingFilter filter = new WebSpherePreAuthenticatedProcessingFilter(helper);
        assertEquals("jerry", filter.getPreAuthenticatedPrincipal(new MockHttpServletRequest()));
        assertEquals("N/A", filter.getPreAuthenticatedCredentials(new MockHttpServletRequest()));

        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
            public Authentication answer(InvocationOnMock invocation) throws Throwable {
                return (Authentication) invocation.getArguments()[0];
            }
        });
View Full Code Here

        SecurityContextHolder.clearContext();
    }

    @Test
    public void filterChainProceedsOnFailedAuthenticationByDefault() throws Exception {
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        filter.setAuthenticationManager(am);
        filter.afterPropertiesSet();
        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), mock(FilterChain.class));
        assertNull(SecurityContextHolder.getContext().getAuthentication());
    }
View Full Code Here

    }

    /* SEC-881 */
    @Test(expected=BadCredentialsException.class)
    public void exceptionIsThrownOnFailedAuthenticationIfContinueFilterChainOnUnsuccessfulAuthenticationSetToFalse() throws Exception {
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        filter.setContinueFilterChainOnUnsuccessfulAuthentication(false);
        filter.setAuthenticationManager(am);
        filter.afterPropertiesSet();
        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), mock(FilterChain.class));
        assertNull(SecurityContextHolder.getContext().getAuthentication());
View Full Code Here

    // SEC-2045
    @Test
    public void testAfterPropertiesSetInvokesSuper() throws Exception {
        ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
        AuthenticationManager am = mock(AuthenticationManager.class);
        filter.setAuthenticationManager(am);
        filter.afterPropertiesSet();
        assertTrue(filter.initFilterBeanInvoked);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.AuthenticationManager

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.