authentication-manager.adoc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. [[ns-auth-manager]]
  2. == The Authentication Manager and the Namespace
  3. The main interface which provides authentication services in Spring Security is the `AuthenticationManager`.
  4. This is usually an instance of Spring Security's `ProviderManager` class, which you may already be familiar with if you've used the framework before.
  5. If not, it will be covered later, in the <<tech-intro-authentication,technical overview chapter>>.
  6. The bean instance is registered using the `authentication-manager` namespace element.
  7. You can't use a custom `AuthenticationManager` if you are using either HTTP or method security through the namespace, but this should not be a problem as you have full control over the `AuthenticationProvider` s that are used.
  8. You may want to register additional `AuthenticationProvider` beans with the `ProviderManager` and you can do this using the `<authentication-provider>` element with the `ref` attribute, where the value of the attribute is the name of the provider bean you want to add.
  9. For example:
  10. [source,xml]
  11. ----
  12. <authentication-manager>
  13. <authentication-provider ref="casAuthenticationProvider"/>
  14. </authentication-manager>
  15. <bean id="casAuthenticationProvider"
  16. class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
  17. ...
  18. </bean>
  19. ----
  20. Another common requirement is that another bean in the context may require a reference to the `AuthenticationManager`.
  21. You can easily register an alias for the `AuthenticationManager` and use this name elsewhere in your application context.
  22. [source,xml]
  23. ----
  24. <security:authentication-manager alias="authenticationManager">
  25. ...
  26. </security:authentication-manager>
  27. <bean id="customizedFormLoginFilter"
  28. class="com.somecompany.security.web.CustomFormLoginFilter">
  29. <property name="authenticationManager" ref="authenticationManager"/>
  30. ...
  31. </bean>
  32. ----