1

Might be a newbie question. I want to inject CustomAuthenticationProviderInside Spring AuthenticationManager. I found a lot of examples online doing that:

<authentication-manager>

    <authentication-provider ref="CustomAuthenticationProvider"/>

</authentication-manager>

How can I do that using Java Config class?

Mohamed Kamal
  • 357
  • 1
  • 2
  • 10
  • refer the example for CustomerAuthenticationManager. http://stackoverflow.com/questions/31826233/custom-authentication-manager-with-spring-security-and-java-configuration – Manoj Kumar Aug 02 '16 at 11:39

1 Answers1

1

Spring offers one default implementation of AuthenticationManager which is ProviderManager. ProviderManager has a constructor which takes an array of Authentication providers

public ProviderManager(List<AuthenticationProvider> providers) {
    this(providers, null);
}

If you want you can just play with it by extending ProviderManager

public class MyAuthenticationManager extends ProviderManager implements AuthenticationManager{

public MyAuthenticationManager(List<AuthenticationProvider> providers) {
    super(providers);
    providers.forEach(e->System.out.println("Registered providers "+e.getClass().getName()));
   }
}

And then i Java security configuration you can add your custom authentication manager.

@Override
protected AuthenticationManager authenticationManager() throws Exception {
    return new MyAuthenticationManager(Arrays.asList(new CustomAuthenticationProvider()));
}
SeaBiscuit
  • 2,553
  • 4
  • 25
  • 40