Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


When a custom authentication manager is used, only the type and name of the been in the Spring Context needs to be specified.
Spring looks in the application context for a custom implementation of the type org.springframework.security.authentication.AuthenticationProvider with the name "ldap01". So it is important that the AuthenticationBean with the specified name is available in the application context.

An implementation example of an AuthenticationProvider:

Code Block
@Component
public class Ldap01AuthenticationProvider implements AuthenticationProvider {
 
    @Override
    public Authentication authenticate(Authentication authentication) 
      throws AuthenticationException {
        String name = authentication.getName();
        String password = authentication.getCredentials().toString();
         
        if (shouldAuthenticateAgainstThirdPartySystem()) {
            // use the credentials and authenticate against the third-party system
            return new UsernamePasswordAuthenticationToken(name, password, new ArrayList<>());
        } else {
            return null;
        }
    }
 
    @Override
    public boolean supports(Class<?> authentication) {
        return authentication.equals(UsernamePasswordAuthenticationToken.class);
    }
}

...