authentication-manager.adoc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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-id]]
  22. * **id**
  23. This attribute allows you to define an id for the internal instance for use in your own configuration.
  24. It is the same as the alias element, but provides a more consistent experience with elements that use the id attribute.
  25. [[nsa-authentication-manager-children]]
  26. === Child Elements of <authentication-manager>
  27. * <<nsa-authentication-provider,authentication-provider>>
  28. * xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-authentication-provider[ldap-authentication-provider]
  29. [[nsa-authentication-provider]]
  30. == <authentication-provider>
  31. Unless used with a `ref` attribute, this element is shorthand for configuring a `DaoAuthenticationProvider`.
  32. `DaoAuthenticationProvider` loads user information from a `UserDetailsService` and compares the username/password combination with the values supplied at login.
  33. 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).
  34. [[nsa-authentication-provider-parents]]
  35. === Parent Elements of <authentication-provider>
  36. * <<nsa-authentication-manager,authentication-manager>>
  37. [[nsa-authentication-provider-attributes]]
  38. === <authentication-provider> Attributes
  39. [[nsa-authentication-provider-ref]]
  40. * **ref**
  41. Defines a reference to a Spring bean that implements `AuthenticationProvider`.
  42. 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`:
  43. [source,xml]
  44. ----
  45. <security:authentication-manager>
  46. <security:authentication-provider ref="myAuthenticationProvider" />
  47. </security:authentication-manager>
  48. <bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider"/>
  49. ----
  50. [[nsa-authentication-provider-user-service-ref]]
  51. * **user-service-ref**
  52. A reference to a bean that implements UserDetailsService that may be created using the standard bean element or the custom user-service element.
  53. [[nsa-authentication-provider-children]]
  54. === Child Elements of <authentication-provider>
  55. * <<nsa-jdbc-user-service,jdbc-user-service>>
  56. * xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-user-service[ldap-user-service]
  57. * <<nsa-password-encoder,password-encoder>>
  58. * <<nsa-user-service,user-service>>
  59. [[nsa-jdbc-user-service]]
  60. == <jdbc-user-service>
  61. Causes creation of a JDBC-based UserDetailsService.
  62. [[nsa-jdbc-user-service-attributes]]
  63. === <jdbc-user-service> Attributes
  64. [[nsa-jdbc-user-service-authorities-by-username-query]]
  65. * **authorities-by-username-query**
  66. An SQL statement to query for a user's granted authorities given a username.
  67. The default is
  68. [source]
  69. ----
  70. select username, authority from authorities where username = ?
  71. ----
  72. [[nsa-jdbc-user-service-cache-ref]]
  73. * **cache-ref**
  74. Defines a reference to a cache for use with a UserDetailsService.
  75. [[nsa-jdbc-user-service-data-source-ref]]
  76. * **data-source-ref**
  77. The bean ID of the DataSource which provides the required tables.
  78. [[nsa-jdbc-user-service-group-authorities-by-username-query]]
  79. * **group-authorities-by-username-query**
  80. An SQL statement to query user's group authorities given a username.
  81. The default is
  82. +
  83. [source]
  84. ----
  85. select
  86. g.id, g.group_name, ga.authority
  87. from
  88. groups g, group_members gm, group_authorities ga
  89. where
  90. gm.username = ? and g.id = ga.group_id and g.id = gm.group_id
  91. ----
  92. [[nsa-jdbc-user-service-id]]
  93. * **id**
  94. A bean identifier, used for referring to the bean elsewhere in the context.
  95. [[nsa-jdbc-user-service-role-prefix]]
  96. * **role-prefix**
  97. A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "ROLE_").
  98. Use the value "none" for no prefix in cases where the default is non-empty.
  99. [[nsa-jdbc-user-service-users-by-username-query]]
  100. * **users-by-username-query**
  101. An SQL statement to query a username, password, and enabled status given a username.
  102. The default is
  103. +
  104. [source]
  105. ----
  106. select username, password, enabled from users where username = ?
  107. ----
  108. [[nsa-password-encoder]]
  109. == <password-encoder>
  110. 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].
  111. This will result in the bean being injected with the appropriate `PasswordEncoder` instance.
  112. [[nsa-password-encoder-parents]]
  113. === Parent Elements of <password-encoder>
  114. * <<nsa-authentication-provider,authentication-provider>>
  115. * xref:servlet/appendix/namespace/authentication-manager.adoc#nsa-password-compare[password-compare]
  116. [[nsa-password-encoder-attributes]]
  117. === <password-encoder> Attributes
  118. [[nsa-password-encoder-hash]]
  119. * **hash**
  120. Defines the hashing algorithm used on user passwords.
  121. We recommend strongly against using MD4, as it is a very weak hashing algorithm.
  122. [[nsa-password-encoder-ref]]
  123. * **ref**
  124. Defines a reference to a Spring bean that implements `PasswordEncoder`.
  125. [[nsa-user-service]]
  126. == <user-service>
  127. Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements.
  128. Usernames are converted to lower-case internally to allow for case-insensitive lookups, so this should not be used if case-sensitivity is required.
  129. [[nsa-user-service-attributes]]
  130. === <user-service> Attributes
  131. [[nsa-user-service-id]]
  132. * **id**
  133. A bean identifier, used for referring to the bean elsewhere in the context.
  134. [[nsa-user-service-properties]]
  135. * **properties**
  136. The location of a Properties file where each line is in the format of
  137. +
  138. [source]
  139. ----
  140. username=password,grantedAuthority[,grantedAuthority][,enabled|disabled]
  141. ----
  142. [[nsa-user-service-children]]
  143. === Child Elements of <user-service>
  144. * <<nsa-user,user>>
  145. [[nsa-user]]
  146. == <user>
  147. Represents a user in the application.
  148. [[nsa-user-parents]]
  149. === Parent Elements of <user>
  150. * <<nsa-user-service,user-service>>
  151. [[nsa-user-attributes]]
  152. === <user> Attributes
  153. [[nsa-user-authorities]]
  154. * **authorities**
  155. One of more authorities granted to the user.
  156. Separate authorities with a comma (but no space).
  157. For example, "ROLE_USER,ROLE_ADMINISTRATOR"
  158. [[nsa-user-disabled]]
  159. * **disabled**
  160. Can be set to "true" to mark an account as disabled and unusable.
  161. [[nsa-user-locked]]
  162. * **locked**
  163. Can be set to "true" to mark an account as locked and unusable.
  164. [[nsa-user-name]]
  165. * **name**
  166. The username assigned to the user.
  167. [[nsa-user-password]]
  168. * **password**
  169. The password assigned to the user.
  170. This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element).
  171. This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities.
  172. If omitted, the namespace will generate a random value, preventing its accidental use for authentication.
  173. Cannot be empty.