|
| 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 | + |
| 8 | + |
| 9 | +[[nsa-authentication-manager]] |
| 10 | +== <authentication-manager> |
| 11 | +Every Spring Security application which uses the namespace must have include this element somewhere. |
| 12 | +It is responsible for registering the `AuthenticationManager` which provides authentication services to the application. |
| 13 | +All elements which create `AuthenticationProvider` instances should be children of this element. |
| 14 | + |
| 15 | + |
| 16 | +[[nsa-authentication-manager-attributes]] |
| 17 | +=== <authentication-manager> Attributes |
| 18 | + |
| 19 | + |
| 20 | +[[nsa-authentication-manager-alias]] |
| 21 | +* **alias** |
| 22 | +This attribute allows you to define an alias name for the internal instance for use in your own configuration. |
| 23 | + |
| 24 | + |
| 25 | +[[nsa-authentication-manager-erase-credentials]] |
| 26 | +* **erase-credentials** |
| 27 | +If set to true, the AuthenticationManager will attempt to clear any credentials data in the returned Authentication object, once the user has been authenticated. |
| 28 | +Literally it maps to the `eraseCredentialsAfterAuthentication` property of the xref:servlet/authentication/architecture.adoc#servlet-authentication-providermanager[`ProviderManager`]. |
| 29 | + |
| 30 | + |
| 31 | +[[nsa-authentication-manager-id]] |
| 32 | +* **id** |
| 33 | +This attribute allows you to define an id for the internal instance for use in your own configuration. |
| 34 | +It is the same as the alias element, but provides a more consistent experience with elements that use the id attribute. |
| 35 | + |
| 36 | + |
| 37 | +[[nsa-authentication-manager-children]] |
| 38 | +=== Child Elements of <authentication-manager> |
| 39 | + |
| 40 | + |
| 41 | +* <<nsa-authentication-provider,authentication-provider>> |
| 42 | +* xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-authentication-provider[ldap-authentication-provider] |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +[[nsa-authentication-provider]] |
| 47 | +== <authentication-provider> |
| 48 | +Unless used with a `ref` attribute, this element is shorthand for configuring a `DaoAuthenticationProvider`. |
| 49 | +`DaoAuthenticationProvider` loads user information from a `UserDetailsService` and compares the username/password combination with the values supplied at login. |
| 50 | +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). |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +[[nsa-authentication-provider-parents]] |
| 55 | +=== Parent Elements of <authentication-provider> |
| 56 | + |
| 57 | + |
| 58 | +* <<nsa-authentication-manager,authentication-manager>> |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +[[nsa-authentication-provider-attributes]] |
| 63 | +=== <authentication-provider> Attributes |
| 64 | + |
| 65 | + |
| 66 | +[[nsa-authentication-provider-ref]] |
| 67 | +* **ref** |
| 68 | +Defines a reference to a Spring bean that implements `AuthenticationProvider`. |
| 69 | + |
| 70 | +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`: |
| 71 | + |
| 72 | +[source,xml] |
| 73 | +---- |
| 74 | +
|
| 75 | +<security:authentication-manager> |
| 76 | + <security:authentication-provider ref="myAuthenticationProvider" /> |
| 77 | +</security:authentication-manager> |
| 78 | +<bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider"/> |
| 79 | +
|
| 80 | +---- |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +[[nsa-authentication-provider-user-service-ref]] |
| 86 | +* **user-service-ref** |
| 87 | +A reference to a bean that implements UserDetailsService that may be created using the standard bean element or the custom user-service element. |
| 88 | + |
| 89 | + |
| 90 | +[[nsa-authentication-provider-children]] |
| 91 | +=== Child Elements of <authentication-provider> |
| 92 | + |
| 93 | + |
| 94 | +* <<nsa-jdbc-user-service,jdbc-user-service>> |
| 95 | +* xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-user-service[ldap-user-service] |
| 96 | +* <<nsa-password-encoder,password-encoder>> |
| 97 | +* <<nsa-user-service,user-service>> |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +[[nsa-jdbc-user-service]] |
| 102 | +== <jdbc-user-service> |
| 103 | +Causes creation of a JDBC-based UserDetailsService. |
| 104 | + |
| 105 | + |
| 106 | +[[nsa-jdbc-user-service-attributes]] |
| 107 | +=== <jdbc-user-service> Attributes |
| 108 | + |
| 109 | + |
| 110 | +[[nsa-jdbc-user-service-authorities-by-username-query]] |
| 111 | +* **authorities-by-username-query** |
| 112 | +An SQL statement to query for a user's granted authorities given a username. |
| 113 | + |
| 114 | +The default is |
| 115 | + |
| 116 | +[source] |
| 117 | +---- |
| 118 | +select username, authority from authorities where username = ? |
| 119 | +---- |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +[[nsa-jdbc-user-service-cache-ref]] |
| 125 | +* **cache-ref** |
| 126 | +Defines a reference to a cache for use with a UserDetailsService. |
| 127 | + |
| 128 | + |
| 129 | +[[nsa-jdbc-user-service-data-source-ref]] |
| 130 | +* **data-source-ref** |
| 131 | +The bean ID of the DataSource which provides the required tables. |
| 132 | + |
| 133 | + |
| 134 | +[[nsa-jdbc-user-service-group-authorities-by-username-query]] |
| 135 | +* **group-authorities-by-username-query** |
| 136 | +An SQL statement to query user's group authorities given a username. |
| 137 | +The default is |
| 138 | + |
| 139 | ++ |
| 140 | + |
| 141 | +[source] |
| 142 | +---- |
| 143 | +select |
| 144 | +g.id, g.group_name, ga.authority |
| 145 | +from |
| 146 | +groups g, group_members gm, group_authorities ga |
| 147 | +where |
| 148 | +gm.username = ? and g.id = ga.group_id and g.id = gm.group_id |
| 149 | +---- |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +[[nsa-jdbc-user-service-id]] |
| 155 | +* **id** |
| 156 | +A bean identifier, used for referring to the bean elsewhere in the context. |
| 157 | + |
| 158 | + |
| 159 | +[[nsa-jdbc-user-service-role-prefix]] |
| 160 | +* **role-prefix** |
| 161 | +A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "ROLE_"). |
| 162 | +Use the value "none" for no prefix in cases where the default is non-empty. |
| 163 | + |
| 164 | + |
| 165 | +[[nsa-jdbc-user-service-users-by-username-query]] |
| 166 | +* **users-by-username-query** |
| 167 | +An SQL statement to query a username, password, and enabled status given a username. |
| 168 | +The default is |
| 169 | + |
| 170 | ++ |
| 171 | + |
| 172 | +[source] |
| 173 | +---- |
| 174 | +select username, password, enabled from users where username = ? |
| 175 | +---- |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | +[[nsa-password-encoder]] |
| 181 | +== <password-encoder> |
| 182 | +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]. |
| 183 | +This will result in the bean being injected with the appropriate `PasswordEncoder` instance. |
| 184 | + |
| 185 | + |
| 186 | +[[nsa-password-encoder-parents]] |
| 187 | +=== Parent Elements of <password-encoder> |
| 188 | + |
| 189 | + |
| 190 | +* <<nsa-authentication-provider,authentication-provider>> |
| 191 | +* xref:servlet/appendix/namespace/authentication-manager.adoc#nsa-password-compare[password-compare] |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | +[[nsa-password-encoder-attributes]] |
| 196 | +=== <password-encoder> Attributes |
| 197 | + |
| 198 | + |
| 199 | +[[nsa-password-encoder-hash]] |
| 200 | +* **hash** |
| 201 | +Defines the hashing algorithm used on user passwords. |
| 202 | +We recommend strongly against using MD4, as it is a very weak hashing algorithm. |
| 203 | + |
| 204 | + |
| 205 | +[[nsa-password-encoder-ref]] |
| 206 | +* **ref** |
| 207 | +Defines a reference to a Spring bean that implements `PasswordEncoder`. |
| 208 | + |
| 209 | + |
| 210 | +[[nsa-user-service]] |
| 211 | +== <user-service> |
| 212 | +Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements. |
| 213 | +Usernames are converted to lower-case internally to allow for case-insensitive lookups, so this should not be used if case-sensitivity is required. |
| 214 | + |
| 215 | + |
| 216 | +[[nsa-user-service-attributes]] |
| 217 | +=== <user-service> Attributes |
| 218 | + |
| 219 | + |
| 220 | +[[nsa-user-service-id]] |
| 221 | +* **id** |
| 222 | +A bean identifier, used for referring to the bean elsewhere in the context. |
| 223 | + |
| 224 | + |
| 225 | +[[nsa-user-service-properties]] |
| 226 | +* **properties** |
| 227 | +The location of a Properties file where each line is in the format of |
| 228 | + |
| 229 | ++ |
| 230 | + |
| 231 | +[source] |
| 232 | +---- |
| 233 | +username=password,grantedAuthority[,grantedAuthority][,enabled|disabled] |
| 234 | +---- |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | +[[nsa-user-service-children]] |
| 240 | +=== Child Elements of <user-service> |
| 241 | + |
| 242 | + |
| 243 | +* <<nsa-user,user>> |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | +[[nsa-user]] |
| 248 | +== <user> |
| 249 | +Represents a user in the application. |
| 250 | + |
| 251 | + |
| 252 | +[[nsa-user-parents]] |
| 253 | +=== Parent Elements of <user> |
| 254 | + |
| 255 | + |
| 256 | +* <<nsa-user-service,user-service>> |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | +[[nsa-user-attributes]] |
| 261 | +=== <user> Attributes |
| 262 | + |
| 263 | + |
| 264 | +[[nsa-user-authorities]] |
| 265 | +* **authorities** |
| 266 | +One of more authorities granted to the user. |
| 267 | +Separate authorities with a comma (but no space). |
| 268 | +For example, "ROLE_USER,ROLE_ADMINISTRATOR" |
| 269 | + |
| 270 | + |
| 271 | +[[nsa-user-disabled]] |
| 272 | +* **disabled** |
| 273 | +Can be set to "true" to mark an account as disabled and unusable. |
| 274 | + |
| 275 | + |
| 276 | +[[nsa-user-locked]] |
| 277 | +* **locked** |
| 278 | +Can be set to "true" to mark an account as locked and unusable. |
| 279 | + |
| 280 | + |
| 281 | +[[nsa-user-name]] |
| 282 | +* **name** |
| 283 | +The username assigned to the user. |
| 284 | + |
| 285 | + |
| 286 | +[[nsa-user-password]] |
| 287 | +* **password** |
| 288 | +The password assigned to the user. |
| 289 | +This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element). |
| 290 | +This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities. |
| 291 | +If omitted, the namespace will generate a random value, preventing its accidental use for authentication. |
| 292 | +Cannot be empty. |
0 commit comments