Search in sources :

Example 6 with ProviderManager

use of org.springframework.security.authentication.ProviderManager in project spring-security-oauth by spring-projects.

the class AuthorizationServerEndpointsConfigurer method addUserDetailsService.

private void addUserDetailsService(DefaultTokenServices tokenServices, UserDetailsService userDetailsService) {
    if (userDetailsService != null) {
        PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
        provider.setPreAuthenticatedUserDetailsService(new UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken>(userDetailsService));
        tokenServices.setAuthenticationManager(new ProviderManager(Arrays.<AuthenticationProvider>asList(provider)));
    }
}
Also used : PreAuthenticatedAuthenticationProvider(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider) ProviderManager(org.springframework.security.authentication.ProviderManager) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) PreAuthenticatedAuthenticationProvider(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)

Example 7 with ProviderManager

use of org.springframework.security.authentication.ProviderManager in project spring-boot by spring-projects.

the class ManagementWebSecurityAutoConfigurationTests method getUser.

private UserDetails getUser() {
    ProviderManager parent = (ProviderManager) this.context.getBean(AuthenticationManager.class);
    DaoAuthenticationProvider provider = (DaoAuthenticationProvider) parent.getProviders().get(0);
    UserDetailsService service = (UserDetailsService) ReflectionTestUtils.getField(provider, "userDetailsService");
    UserDetails user = service.loadUserByUsername("user");
    return user;
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) UserDetails(org.springframework.security.core.userdetails.UserDetails) DaoAuthenticationProvider(org.springframework.security.authentication.dao.DaoAuthenticationProvider) ProviderManager(org.springframework.security.authentication.ProviderManager) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService)

Aggregations

ProviderManager (org.springframework.security.authentication.ProviderManager)7 Test (org.junit.Test)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 DaoAuthenticationProvider (org.springframework.security.authentication.dao.DaoAuthenticationProvider)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)1 DefaultAuthenticationEventPublisher (org.springframework.security.authentication.DefaultAuthenticationEventPublisher)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1 PreAuthenticatedAuthenticationProvider (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1