Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.AuthenticationManager


        });
    }

    @Bean
    Security security() {
        AuthenticationManager authenticationManager;
        try {
            authenticationManager = applicationContext.getBean(AuthenticationManager.class);
        } catch (NoSuchBeanDefinitionException ex) {
            authenticationManager = null;
        }
View Full Code Here


    public void testNormalOperation() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/j_spring_cas_security_check");
        request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");

        CasAuthenticationFilter filter = new CasAuthenticationFilter();
        filter.setAuthenticationManager(new AuthenticationManager() {
            public Authentication authenticate(Authentication a) {
                return a;
            }
        });
View Full Code Here

    }

    @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");
            }
        });
View Full Code Here

    }

    @Test
    public void testDoFilterAuthenticateAll() throws Exception {
        AuthenticationSuccessHandler successHandler = mock(AuthenticationSuccessHandler.class);
        AuthenticationManager manager = mock(AuthenticationManager.class);
        Authentication authentication = new TestingAuthenticationToken("un", "pwd","ROLE_USER");
        when(manager.authenticate(any(Authentication.class))).thenReturn(authentication);
        ServiceProperties serviceProperties = new ServiceProperties();
        serviceProperties.setAuthenticateAllArtifacts(true);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setParameter("ticket", "ST-1-123");
        request.setRequestURI("/authenticate");
View Full Code Here

        }

        DefaultAuthenticationEventPublisher eventPublisher = objectPostProcessor.postProcess(new DefaultAuthenticationEventPublisher());
        localConfigureAuthenticationBldr.authenticationEventPublisher(eventPublisher);

        AuthenticationManager authenticationManager = authenticationManager();
        authenticationBuilder.parentAuthenticationManager(authenticationManager);
        http = new HttpSecurity(objectPostProcessor,authenticationBuilder, localConfigureAuthenticationBldr.getSharedObjects());
        http.setSharedObject(UserDetailsService.class, userDetailsService());
        http.setSharedObject(ApplicationContext.class, context);
        http.setSharedObject(ContentNegotiationStrategy.class, contentNegotiationStrategy);
View Full Code Here

        filter = new OpenIDAuthenticationFilter();
        filter.setConsumer(new MockOpenIDConsumer(REDIRECT_URL));
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        filter.setAuthenticationSuccessHandler(new SavedRequestAwareAuthenticationSuccessHandler());
        successHandler.setDefaultTargetUrl(DEFAULT_TARGET_URL);
        filter.setAuthenticationManager(new AuthenticationManager() {
            public Authentication authenticate(Authentication a) {
                return a;
            }
        });
        filter.afterPropertiesSet();
View Full Code Here

    }

    @Override
    public void configure(B http) throws Exception {
        AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
        BasicAuthenticationFilter basicAuthenticationFilter = new BasicAuthenticationFilter(authenticationManager, authenticationEntryPoint);
        if(authenticationDetailsSource != null) {
            basicAuthenticationFilter.setAuthenticationDetailsSource(authenticationDetailsSource);
        }
        basicAuthenticationFilter = postProcess(basicAuthenticationFilter);
View Full Code Here

                "<authentication-manager>" +
                "  <authentication-provider>" +
                "    <jdbc-user-service data-source-ref='dataSource'/>" +
                "  </authentication-provider>" +
                "</authentication-manager>" + DATA_SOURCE);
        AuthenticationManager mgr = (AuthenticationManager) appContext.getBean(BeanIds.AUTHENTICATION_MANAGER);
        mgr.authenticate(new UsernamePasswordAuthenticationToken("rod", "koala"));
    }
View Full Code Here

            if(isAuthenticated()) {
                throw new ServletException("Cannot perform login for '"
                        + username + "' already authenticated as '"
                        + getRemoteUser() + "'");
            }
            AuthenticationManager authManager = authenticationManager;
            if(authManager == null) {
                logger.debug("authenticationManager is null, so allowing original HttpServletRequest to handle login");
                super.login(username, password);
                return;
            }
            Authentication authentication;
            try {
                authentication = authManager.authenticate(new UsernamePasswordAuthenticationToken(username,password));
            } catch(AuthenticationException loginFailed) {
                SecurityContextHolder.clearContext();
                throw new ServletException(loginFailed.getMessage(), loginFailed);
            }
            SecurityContextHolder.getContext().setAuthentication(authentication);
View Full Code Here

    @Test
    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

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.