You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/appendix/faq.adoc
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,12 +138,13 @@ If you use hashed passwords, make sure the value stored in your database is _exa
138
138
=== My application goes into an "`endless loop`" when I try to log in. What is going on?
139
139
140
140
A common user problem with infinite loop and redirecting to the login page is caused by accidentally configuring the login page as a "`secured`" resource.
141
-
Make sure your configuration allows anonymous access to the login page, either by excluding it from the security filter chain or marking it as requiring `ROLE_ANONYMOUS`.
142
-
143
-
If your `AccessDecisionManager` includes an `AuthenticatedVoter`, you can use the `IS_AUTHENTICATED_ANONYMOUSLY` attribute. This is automatically available if you use the standard namespace configuration setup.
144
-
145
-
From Spring Security 2.0.1 onwards, when you use namespace-based configuration, a check is made on loading the application context and a warning message logged if your login page appears to be protected.
141
+
Make sure your configuration allows anonymous access to the login page.
142
+
You can do so with the xref:servlet/authorization/authorize-http-requests.adoc[`authorizeHttpRequests`] DSL.
146
143
144
+
[TIP]
145
+
====
146
+
When you use namespace- or DSL-based configuration, a check is made on loading the application context and a warning message logged if your login page appears to be protected.
147
+
====
147
148
148
149
[[appendix-faq-anon-access-denied]]
149
150
=== I get an exception with the message "Access is denied (user is anonymous);". What's wrong?
@@ -382,16 +383,16 @@ You should probably read the chapters on namespace parsing in the standard Sprin
382
383
383
384
384
385
[[appendix-faq-role-prefix]]
385
-
=== What does "ROLE_" mean and why do I need it on my role names?
386
+
=== What does "ROLE_" mean?
386
387
387
-
Spring Security has a voter-based architecture, which means that an access decision is made by a series of `AccessDecisionVoter` instances.
388
-
The voters act on the "`configuration attributes`", which are specified for a secured resource (such as a method invocation). With this approach, not all attributes may be relevant to all voters, and a voter needs to know when it should ignore an attribute (abstain) and when it should vote to grant or deny access based on the attribute value.
389
-
The most common voter is the `RoleVoter`, which, by default, votes whenever it finds an attribute with the `ROLE_` prefix.
390
-
It makes a simple comparison of the attribute (such as `ROLE_USER`) with the names of the authorities that the current user has been assigned.
391
-
If it finds a match (they have an authority called `ROLE_USER`), it votes to grant access. Otherwise, it votes to deny access.
388
+
`ROLE_` is a way to identify the nature of a given authority.
389
+
An authority prefixed by `ROLE_` means that this authority is a role, likely derived from an RBAC authorization model.
392
390
393
-
You can change the prefix by setting the `rolePrefix` property of `RoleVoter`. If you need only to use roles in your application and have no need for other custom voters, you can set the prefix to a blank string. In that case, the `RoleVoter` treats all attributes as roles.
391
+
Having a prefix allows for clear differentiation from OAuth 2.0 scopes (which use `SCOPE_`) and authorities granted from other sources as well.
394
392
393
+
You may choose to not prefix your authorities.
394
+
Modern Spring Security authorization components either allow you to supply the entire authority name, rendering the prefix unnecessary.
395
+
An example of this is how xref:servlet/authorization/authorize-http-requests.adoc[`authorizeHttpRequests`] and xref:servlet/authorization/method-security.adoc[`@PreAuthorize`] allow you to call `hasAuthority` or `hasRole`.
395
396
396
397
[[appendix-faq-what-dependencies]]
397
398
=== How do I know which dependencies to add to my application to work with Spring Security?
@@ -145,6 +150,11 @@ You can define zero or more of these within the `global-method-security` element
145
150
[[nsa-after-invocation-provider-attributes]]
146
151
=== <after-invocation-provider> Attributes
147
152
153
+
[NOTE]
154
+
=====
155
+
`<after-invocation-provider>` is deprecated in favor of `<method-security>` and xref:servlet/authorization/method-security.adoc[`@PostFilter` and `@PostAuthorize`].
156
+
If you need to use `<after-invocation-provider>`, please include the `spring-security-access` dependency in your build configuration while planning to migrate to a modern option.
157
+
=====
148
158
149
159
[[nsa-after-invocation-provider-ref]]
150
160
* **ref**
@@ -179,6 +189,11 @@ Only applies if these annotations are enabled.
179
189
== <invocation-attribute-factory>
180
190
Defines the PrePostInvocationAttributeFactory instance which is used to generate pre and post invocation metadata from the annotated methods.
181
191
192
+
[NOTE]
193
+
=====
194
+
`<invocation-attribute-factory>` is deprecated in favor of `<method-security>` and xref:servlet/authorization/method-security.adoc[`@PostFilter` and `@PostAuthorize`].
195
+
If you need to use `<invocation-attribute-factory>`, please include the `spring-security-access` dependency in your build configuration while planning to migrate to a modern option.
196
+
=====
182
197
183
198
[[nsa-invocation-attribute-factory-parents]]
184
199
=== Parent Elements of <invocation-attribute-factory>
@@ -201,6 +216,11 @@ Defines a reference to a Spring bean Id.
201
216
== <post-invocation-advice>
202
217
Customizes the `PostInvocationAdviceProvider` with the ref as the `PostInvocationAuthorizationAdvice` for the <pre-post-annotation-handling> element.
203
218
219
+
[NOTE]
220
+
=====
221
+
`<post-invocation-advice>` is deprecated in favor of `<method-security>` and xref:servlet/authorization/method-security.adoc[`@PostFilter` and `@PostAuthorize`].
222
+
If you need to use `<post-invocation-advice>`, please include the `spring-security-access` dependency in your build configuration while planning to migrate to a modern option.
223
+
=====
204
224
205
225
[[nsa-post-invocation-advice-parents]]
206
226
=== Parent Elements of <post-invocation-advice>
@@ -223,6 +243,11 @@ Defines a reference to a Spring bean Id.
223
243
== <pre-invocation-advice>
224
244
Customizes the `PreInvocationAuthorizationAdviceVoter` with the ref as the `PreInvocationAuthorizationAdviceVoter` for the <pre-post-annotation-handling> element.
225
245
246
+
[NOTE]
247
+
=====
248
+
`<pre-invocation-advice>` is deprecated in favor of `<method-security>` and xref:servlet/authorization/method-security.adoc[`@PreFilter` and `@PreAuthorize`].
249
+
If you need to use `<pre-invocation-advice>`, please include the `spring-security-access` dependency in your build configuration while planning to migrate to a modern option.
250
+
=====
226
251
227
252
[[nsa-pre-invocation-advice-parents]]
228
253
=== Parent Elements of <pre-invocation-advice>
@@ -247,7 +272,6 @@ Defines a reference to a Spring bean Id.
247
272
Rather than defining security attributes on an individual method or class basis using the `@Secured` annotation, you can define cross-cutting security constraints across whole sets of methods and interfaces in your service layer using the `<protect-pointcut>` element.
248
273
You can find an example in the xref:servlet/authorization/method-security.adoc#ns-protect-pointcut[namespace introduction].
249
274
250
-
251
275
[[nsa-protect-pointcut-parents]]
252
276
=== Parent Elements of <protect-pointcut>
253
277
@@ -293,7 +317,6 @@ Optional AuthorizationManager bean ID to be used instead of the default (superse
293
317
* **access-decision-manager-ref**
294
318
Optional AccessDecisionManager bean ID to be used by the created method security interceptor.
295
319
296
-
297
320
[[nsa-intercept-methods-children]]
298
321
=== Child Elements of <intercept-methods>
299
322
@@ -306,6 +329,11 @@ Optional AccessDecisionManager bean ID to be used by the created method security
306
329
== <method-security-metadata-source>
307
330
Creates a MethodSecurityMetadataSource instance
308
331
332
+
[NOTE]
333
+
=====
334
+
`<method-security-metadata-source>` is deprecated in favor of xref:servlet/authorization/method-security.adoc[`<method-security>`].
335
+
If you need to use `<method-security-metadata-source>`, please include the `spring-security-access` dependency in your build configuration while planning to migrate to a modern option.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/acls.adoc
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,9 +17,9 @@ When you use Spring Security as the foundation, you have several possible approa
17
17
* Write your business methods to enforce the security.
18
18
You could consult a collection within the `Customer` domain object instance to determine which users have access.
19
19
By using `SecurityContextHolder.getContext().getAuthentication()`, you can access the `Authentication` object.
20
-
* Write an `AccessDecisionVoter` to enforce the security from the `GrantedAuthority[]` instances stored in the `Authentication` object.
20
+
* Write an `AuthorizationManager` to enforce the security from the `GrantedAuthority[]` instances stored in the `Authentication` object.
21
21
This means that your `AuthenticationManager` needs to populate the `Authentication` with custom `GrantedAuthority[]` objects to represent each of the `Customer` domain object instances to which the principal has access.
22
-
* Write an `AccessDecisionVoter` to enforce the security and open the target `Customer` domain object directly.
22
+
* Write an `AuthorizationManager` to enforce the security and open the target `Customer` domain object directly.
23
23
This would mean your voter needs access to a DAO that lets it retrieve the `Customer` object.
24
24
It can then access the `Customer` object's collection of approved users and make the appropriate decision.
25
25
@@ -29,7 +29,7 @@ The main problems with this include the enhanced difficulty of unit testing and
29
29
Obtaining the `GrantedAuthority[]` instances from the `Authentication` object is also fine but will not scale to large numbers of `Customer` objects.
30
30
If a user can access 5,000 `Customer` objects (unlikely in this case, but imagine if it were a popular vet for a large Pony Club!) the amount of memory consumed and the time required to construct the `Authentication` object would be undesirable.
31
31
The final method, opening the `Customer` directly from external code, is probably the best of the three.
32
-
It achieves separation of concerns and does not misuse memory or CPU cycles, but it is still inefficient in that both the `AccessDecisionVoter` and the eventual business method itself perform a call to the DAO responsible for retrieving the `Customer` object.
32
+
It achieves separation of concerns and does not misuse memory or CPU cycles, but it is still inefficient in that both the `AuthorizationManager` and the eventual business method itself perform a call to the DAO responsible for retrieving the `Customer` object.
33
33
Two accesses per method invocation is clearly undesirable.
34
34
In addition, with every approach listed, you need to write your own access control list (ACL) persistence and business logic from scratch.
35
35
@@ -40,6 +40,11 @@ Fortunately, there is another alternative, which we discuss later.
40
40
Spring Security's ACL services are shipped in the `spring-security-acl-xxx.jar`.
41
41
You need to add this JAR to your classpath to use Spring Security's domain object instance security capabilities.
42
42
43
+
[NOTE]
44
+
====
45
+
If you need access to the legacy Access API that includes `AclEntryVoter`, please also include `spring-security-access-xxx.jar`.
46
+
====
47
+
43
48
Spring Security's domain object instance security capabilities center on the concept of an access control list (ACL).
44
49
Every domain object instance in your system has its own ACL, and the ACL records details of who can and cannot work with that domain object.
45
50
With this in mind, Spring Security provides three main ACL-related capabilities to your application:
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/architecture.adoc
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ This section describes the Spring Security architecture that applies to authoriz
10
10
== Authorities
11
11
xref:servlet/authentication/architecture.adoc#servlet-authentication-authentication[`Authentication`] discusses how all `Authentication` implementations store a list of `GrantedAuthority` objects.
12
12
These represent the authorities that have been granted to the principal.
13
-
The `GrantedAuthority` objects are inserted into the `Authentication` object by the `AuthenticationManager` and are later read by `AccessDecisionManager` instances when making authorization decisions.
13
+
The `GrantedAuthority` objects are inserted into the `Authentication` object by the `AuthenticationManager` and are later read by `AuthorizationManager` instances when making authorization decisions.
14
14
15
15
The `GrantedAuthority` interface has only one method:
16
16
@@ -347,6 +347,28 @@ Spring Security contains some legacy components.
347
347
Since they are not yet removed, documentation is included for historical purposes.
348
348
Their recommended replacements are above.
349
349
350
+
When accessing legacy authorization components, please also include the `spring-security-access` dependency like so:
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/index.adoc
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,4 +11,11 @@ You should consider attaching authorization rules to xref:servlet/authorization/
11
11
In either case, you can listen and react to xref:servlet/authorization/events.adoc[authorization events] that each authorization check publishes.
12
12
Below there is also wealth of detail about xref:servlet/authorization/architecture.adoc[how Spring Security authorization works] and how, having established a basic model, it can be fine-tuned.
13
13
14
+
[NOTE]
15
+
====
16
+
As of Spring Security 7, the Access API (`AccessDecisionManager`, `AccessDecisionVoter`, etc.) are moved to a legacy module, `spring-security-access`.
17
+
For new applications, there is no need to include the dependency.
18
+
For older applications that have not yet migrated to the Authorization API, this module is available to assist your continued migration efforts.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/whats-new.adoc
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ Each section that follows will indicate the more notable removals as well as the
14
14
* Removed `AuthorizationManager#check` in favor of `AuthorizationManager#authorize`
15
15
* Added xref:servlet/authorization/architecture.adoc#authz-authorization-manager-factory[`AuthorizationManagerFactory`] for creating `AuthorizationManager` instances in xref:servlet/authorization/authorize-http-requests.adoc#customizing-authorization-managers[request-based] and xref:servlet/authorization/method-security.adoc#customizing-authorization-managers[method-based] authorization components
16
16
* Added `Authentication.Builder` for mutating and merging `Authentication` instances
17
+
* Moved Access API (`AccessDecisionManager`, `AccessDecisionVoter`, etc.) to a new module, `spring-security-access`
0 commit comments