2
0

authentication-manager.adoc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. [[nsa-authentication]]
  2. = Authentication Services
  3. Before Spring Security 3.0, an `AuthenticationManager` was automatically registered internally.
  4. Now you must register one explicitly using the `<authentication-manager>` element.
  5. This creates an instance of Spring Security's `ProviderManager` class, which needs to be configured with a list of one or more `AuthenticationProvider` instances.
  6. These can either be created using syntax elements provided by the namespace, or they can be standard bean definitions, marked for addition to the list using the `authentication-provider` element.
  7. [[nsa-authentication-manager]]
  8. == <authentication-manager>
  9. Every Spring Security application which uses the namespace must have include this element somewhere.
  10. It is responsible for registering the `AuthenticationManager` which provides authentication services to the application.
  11. All elements which create `AuthenticationProvider` instances should be children of this element.
  12. [[nsa-authentication-manager-attributes]]
  13. === <authentication-manager> Attributes
  14. [[nsa-authentication-manager-alias]]
  15. * **alias**
  16. This attribute allows you to define an alias name for the internal instance for use in your own configuration.
  17. [[nsa-authentication-manager-erase-credentials]]
  18. * **erase-credentials**
  19. If set to true, the AuthenticationManager will attempt to clear any credentials data in the returned Authentication object, once the user has been authenticated.
  20. Literally it maps to the `eraseCredentialsAfterAuthentication` property of the xref:servlet/authentication/architecture.adoc#servlet-authentication-providermanager[`ProviderManager`].
  21. [[nsa-authentication-manager-observation-registry-ref]]
  22. * **observation-registry-ref**
  23. A reference to the `ObservationRegistry` used for the `FilterChain` and related components
  24. [[nsa-authentication-manager-id]]
  25. * **id**
  26. This attribute allows you to define an id for the internal instance for use in your own configuration.
  27. It is the same as the alias element, but provides a more consistent experience with elements that use the id attribute.
  28. [[nsa-authentication-manager-children]]
  29. === Child Elements of <authentication-manager>
  30. * <<nsa-authentication-provider,authentication-provider>>
  31. * xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-authentication-provider[ldap-authentication-provider]
  32. [[nsa-authentication-provider]]
  33. == <authentication-provider>
  34. Unless used with a `ref` attribute, this element is shorthand for configuring a `DaoAuthenticationProvider`.
  35. `DaoAuthenticationProvider` loads user information from a `UserDetailsService` and compares the username/password combination with the values supplied at login.
  36. The `UserDetailsService` instance can be defined either by using an available namespace element (`jdbc-user-service` or by using the `user-service-ref` attribute to point to a bean defined elsewhere in the application context).
  37. [[nsa-authentication-provider-parents]]
  38. === Parent Elements of <authentication-provider>
  39. * <<nsa-authentication-manager,authentication-manager>>
  40. [[nsa-authentication-provider-attributes]]
  41. === <authentication-provider> Attributes
  42. [[nsa-authentication-provider-ref]]
  43. * **ref**
  44. Defines a reference to a Spring bean that implements `AuthenticationProvider`.
  45. If you have written your own `AuthenticationProvider` implementation (or want to configure one of Spring Security's own implementations as a traditional bean for some reason, then you can use the following syntax to add it to the internal list of `ProviderManager`:
  46. [source,xml]
  47. ----
  48. <security:authentication-manager>
  49. <security:authentication-provider ref="myAuthenticationProvider" />
  50. </security:authentication-manager>
  51. <bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider"/>
  52. ----
  53. [[nsa-authentication-provider-user-service-ref]]
  54. * **user-service-ref**
  55. A reference to a bean that implements UserDetailsService that may be created using the standard bean element or the custom user-service element.
  56. [[nsa-authentication-provider-children]]
  57. === Child Elements of <authentication-provider>
  58. * <<nsa-jdbc-user-service,jdbc-user-service>>
  59. * xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-user-service[ldap-user-service]
  60. * <<nsa-password-encoder,password-encoder>>
  61. * <<nsa-user-service,user-service>>
  62. [[nsa-jdbc-user-service]]
  63. == <jdbc-user-service>
  64. Causes creation of a JDBC-based UserDetailsService.
  65. [[nsa-jdbc-user-service-attributes]]
  66. === <jdbc-user-service> Attributes
  67. [[nsa-jdbc-user-service-authorities-by-username-query]]
  68. * **authorities-by-username-query**
  69. An SQL statement to query for a user's granted authorities given a username.
  70. The default is
  71. [source]
  72. ----
  73. select username, authority from authorities where username = ?
  74. ----
  75. [[nsa-jdbc-user-service-cache-ref]]
  76. * **cache-ref**
  77. Defines a reference to a cache for use with a UserDetailsService.
  78. [[nsa-jdbc-user-service-data-source-ref]]
  79. * **data-source-ref**
  80. The bean ID of the DataSource which provides the required tables.
  81. [[nsa-jdbc-user-service-group-authorities-by-username-query]]
  82. * **group-authorities-by-username-query**
  83. An SQL statement to query user's group authorities given a username.
  84. The default is
  85. +
  86. [source]
  87. ----
  88. select
  89. g.id, g.group_name, ga.authority
  90. from
  91. groups g, group_members gm, group_authorities ga
  92. where
  93. gm.username = ? and g.id = ga.group_id and g.id = gm.group_id
  94. ----
  95. [[nsa-jdbc-user-service-id]]
  96. * **id**
  97. A bean identifier, used for referring to the bean elsewhere in the context.
  98. [[nsa-jdbc-user-service-role-prefix]]
  99. * **role-prefix**
  100. A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "ROLE_").
  101. Use the value "none" for no prefix in cases where the default is non-empty.
  102. [[nsa-jdbc-user-service-users-by-username-query]]
  103. * **users-by-username-query**
  104. An SQL statement to query a username, password, and enabled status given a username.
  105. The default is
  106. +
  107. [source]
  108. ----
  109. select username, password, enabled from users where username = ?
  110. ----
  111. [[nsa-password-encoder]]
  112. == <password-encoder>
  113. Authentication providers can optionally be configured to use a password encoder as described in the xref:features/authentication/password-storage.adoc#authentication-password-storage[Password Storage].
  114. This will result in the bean being injected with the appropriate `PasswordEncoder` instance.
  115. [[nsa-password-encoder-parents]]
  116. === Parent Elements of <password-encoder>
  117. * <<nsa-authentication-provider,authentication-provider>>
  118. * xref:servlet/appendix/namespace/authentication-manager.adoc#nsa-password-compare[password-compare]
  119. [[nsa-password-encoder-attributes]]
  120. === <password-encoder> Attributes
  121. [[nsa-password-encoder-hash]]
  122. * **hash**
  123. Defines the hashing algorithm used on user passwords.
  124. We recommend strongly against using MD4, as it is a very weak hashing algorithm.
  125. [[nsa-password-encoder-ref]]
  126. * **ref**
  127. Defines a reference to a Spring bean that implements `PasswordEncoder`.
  128. [[nsa-user-service]]
  129. == <user-service>
  130. Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements.
  131. Usernames are converted to lower-case internally to allow for case-insensitive lookups, so this should not be used if case-sensitivity is required.
  132. [[nsa-user-service-attributes]]
  133. === <user-service> Attributes
  134. [[nsa-user-service-id]]
  135. * **id**
  136. A bean identifier, used for referring to the bean elsewhere in the context.
  137. [[nsa-user-service-properties]]
  138. * **properties**
  139. The location of a Properties file where each line is in the format of
  140. +
  141. [source]
  142. ----
  143. username=password,grantedAuthority[,grantedAuthority][,enabled|disabled]
  144. ----
  145. [[nsa-user-service-children]]
  146. === Child Elements of <user-service>
  147. * <<nsa-user,user>>
  148. [[nsa-user]]
  149. == <user>
  150. Represents a user in the application.
  151. [[nsa-user-parents]]
  152. === Parent Elements of <user>
  153. * <<nsa-user-service,user-service>>
  154. [[nsa-user-attributes]]
  155. === <user> Attributes
  156. [[nsa-user-authorities]]
  157. * **authorities**
  158. One of more authorities granted to the user.
  159. Separate authorities with a comma (but no space).
  160. For example, "ROLE_USER,ROLE_ADMINISTRATOR"
  161. [[nsa-user-disabled]]
  162. * **disabled**
  163. Can be set to "true" to mark an account as disabled and unusable.
  164. [[nsa-user-locked]]
  165. * **locked**
  166. Can be set to "true" to mark an account as locked and unusable.
  167. [[nsa-user-name]]
  168. * **name**
  169. The username assigned to the user.
  170. [[nsa-user-password]]
  171. * **password**
  172. The password assigned to the user.
  173. This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element).
  174. This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities.
  175. If omitted, the namespace will generate a random value, preventing its accidental use for authentication.
  176. Cannot be empty.