Search in sources :

Example 1 with AuthenticationProvider

use of org.springframework.security.authentication.AuthenticationProvider in project cas by apereo.

the class CasLdapUserDetailsManagerConfigurer method configure.

@Override
public void configure(final B builder) throws Exception {
    final AuthenticationProvider provider = postProcess(buildLdapAuthenticationProvider());
    builder.authenticationProvider(provider);
}
Also used : AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) LdapAuthenticationProvider(org.apereo.cas.web.ldap.LdapAuthenticationProvider)

Example 2 with AuthenticationProvider

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

the class SecurityConfig method authenticationProvider.

@Bean
public AuthenticationProvider authenticationProvider() {
    Assert.notNull(myUserRepository);
    return new AuthenticationProvider() {

        public boolean supports(Class<?> authentication) {
            return true;
        }

        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            Object principal = authentication.getPrincipal();
            String username = String.valueOf(principal);
            User user = myUserRepository.findByUsername(username);
            if (user == null) {
                throw new UsernameNotFoundException("No user for principal " + principal);
            }
            if (!authentication.getCredentials().equals(user.getPassword())) {
                throw new BadCredentialsException("Invalid password");
            }
            return new TestingAuthenticationToken(principal, null, "ROLE_USER");
        }
    };
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(org.springframework.security.config.annotation.issue50.domain.User) Authentication(org.springframework.security.core.Authentication) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Bean(org.springframework.context.annotation.Bean)

Example 3 with AuthenticationProvider

use of org.springframework.security.authentication.AuthenticationProvider 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)

Aggregations

AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)3 LdapAuthenticationProvider (org.apereo.cas.web.ldap.LdapAuthenticationProvider)1 Bean (org.springframework.context.annotation.Bean)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 ProviderManager (org.springframework.security.authentication.ProviderManager)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 User (org.springframework.security.config.annotation.issue50.domain.User)1 Authentication (org.springframework.security.core.Authentication)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PreAuthenticatedAuthenticationProvider (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1