provider-manager.adoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. [[servlet-authentication-providermanager]]
  2. = ProviderManager
  3. :figures: images/servlet/authentication/architecture
  4. {security-api-url}org/springframework/security/authentication/ProviderManager.html[`ProviderManager`] is the most commonly used implementation of <<servlet-authentication-authenticationmanager,`AuthenticationManager`>>.
  5. `ProviderManager` delegates to a `List` of <<servlet-authentication-authenticationprovider,``AuthenticationProvider``s>>.
  6. // FIXME: link to AuthenticationProvider
  7. Each `AuthenticationProvider` has an opportunity to indicate that authentication should be successful, fail, or indicate it cannot make a decision and allow a downstream `AuthenticationProvider` to decide.
  8. If none of the configured ``AuthenticationProvider``s can authenticate, then authentication will fail with a `ProviderNotFoundException` which is a special `AuthenticationException` that indicates the `ProviderManager` was not configured to support the type of `Authentication` that was passed into it.
  9. image::{figures}/providermanager.png[]
  10. In practice each `AuthenticationProvider` knows how to perform a specific type of authentication.
  11. For example, one `AuthenticationProvider` might be able to validate a username/password, while another might be able to authenticate a SAML assertion.
  12. This allows each `AuthenticationProvider` to do a very specific type of authentication, while supporting multiple types of authentication and only exposing a single `AuthenticationManager` bean.
  13. `ProviderManager` also allows configuring an optional parent `AuthenticationManager` which is consulted in the event that no `AuthenticationProvider` can perform authentication.
  14. The parent can be any type of `AuthenticationManager`, but it is often an instance of `ProviderManager`.
  15. image::{figures}/providermanager-parent.png[]
  16. In fact, multiple `ProviderManager` instances might share the same parent `AuthenticationManager`.
  17. This is somewhat common in scenarios where there are multiple <<servlet-securityfilterchain,`SecurityFilterChain`>> instances that have some authentication in common (the shared parent `AuthenticationManager`), but also different authentication mechanisms (the different `ProviderManager` instances).
  18. image::{figures}/providermanagers-parent.png[]
  19. [[servlet-authentication-providermanager-erasing-credentials]]
  20. By default `ProviderManager` will attempt to clear any sensitive credentials information from the `Authentication` object which is returned by a successful authentication request.
  21. This prevents information like passwords being retained longer than necessary in the `HttpSession`.
  22. This may cause issues when you are using a cache of user objects, for example, to improve performance in a stateless application.
  23. If the `Authentication` contains a reference to an object in the cache (such as a `UserDetails` instance) and this has its credentials removed, then it will no longer be possible to authenticate against the cached value.
  24. You need to take this into account if you are using a cache.
  25. An obvious solution is to make a copy of the object first, either in the cache implementation or in the `AuthenticationProvider` which creates the returned `Authentication` object.
  26. Alternatively, you can disable the `eraseCredentialsAfterAuthentication` property on `ProviderManager`.
  27. See the {security-api-url}org/springframework/security/authentication/ProviderManager.html[Javadoc] for more information.