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/migration.adoc
+301
Original file line number
Diff line number
Diff line change
@@ -367,6 +367,98 @@ companion object {
367
367
----
368
368
====
369
369
370
+
==== Replace any custom method-security ``AccessDecisionManager``s
371
+
372
+
Your application may have a custom {security-api-url}org/springframework/security/access/AccessDecisionManager.html[`AccessDecisionManager`] or {security-api-url}org/springframework/security/access/AccessDecisionVoter.html[`AccessDecisionVoter`] arrangement.
373
+
The preparation strategy will depend on your reason for each arrangement.
374
+
Read on to find the best match for your situation.
375
+
376
+
===== I use `UnanimousBased`
377
+
378
+
If your application uses {security-api-url}org/springframework/security/access/vote/UnanimousBased.html[`UnanimousBased`] with the default voters, you likely need do nothing since unanimous-based is the default behavior with {security-api-url}org/springframework/security/config/annotation/method/configuration/EnableMethodSecurity.html[`@EnableMethodSecurity`].
379
+
380
+
However, if you do discover that you cannot accept the default authorization managers, you can use `AuthorizationManagers.allOf` to compose your own arrangement.
381
+
Having done that, please follow the details in the reference manual for xref:servlet/authorization/method-security.adoc#jc-method-security-custom-authorization-manager[adding a custom `AuthorizationManager`].
382
+
383
+
===== I use `AffirmativeBased`
384
+
385
+
If your application uses {security-api-url}org/springframework/security/access/vote/AffirmativeBased.html[`AffirmativeBased`], then you can construct an equivalent {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`], like so:
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/method-security.adoc#jc-method-security-custom-authorization-manager[adding a custom `AuthorizationManager`].
406
+
407
+
===== I use `ConsensusBased`
408
+
409
+
There is no framework-provided equivalent for {security-api-url}org/springframework/security/access/vote/ConsensusBased.html[`ConsensusBased`].
410
+
In that case, please implement a composite {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] that takes the set of delegate ``AuthorizationManager``s into account.
411
+
412
+
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/method-security.adoc#jc-method-security-custom-authorization-manager[adding a custom `AuthorizationManager`].
413
+
414
+
===== I use a custom `AccessDecisionVoter`
415
+
416
+
You should either change the class to implement {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] or create an adapter.
417
+
418
+
Without knowing what your custom voter is doing, it is impossible to recommend a general-purpose solution.
419
+
By way of example, though, here is what adapting {security-api-url}org/springframework/security/access/SecurityMetadataSource.html[`SecurityMetadataSource`] and {security-api-url}org/springframework/security/access/AccessDecisionVoter.html[`AccessDecisionVoter`] for `@PreAuthorize` would look like:
420
+
421
+
====
422
+
.Java
423
+
[source,java,role="primary"]
424
+
----
425
+
public final class PreAuthorizeAuthorizationManagerAdapter implements AuthorizationManager<MethodInvocation> {
426
+
private final SecurityMetadataSource metadata;
427
+
private final AccessDecisionVoter voter;
428
+
429
+
public PreAuthorizeAuthorizationManagerAdapter(MethodSecurityExpressionHandler expressionHandler) {
int decision = this.voter.vote(authentication.get(), invocation, attributes);
441
+
if (decision == ACCESS_GRANTED) {
442
+
return new AuthorizationDecision(true);
443
+
}
444
+
if (decision == ACCESS_DENIED) {
445
+
return new AuthorizationDecision(false);
446
+
}
447
+
return null; // abstain
448
+
}
449
+
}
450
+
----
451
+
====
452
+
453
+
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/method-security.adoc#jc-method-security-custom-authorization-manager[adding a custom `AuthorizationManager`].
454
+
455
+
===== I use a custom `AfterInvocationManager`
456
+
457
+
{security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] replaces both {security-api-url}org/springframework/security/access/AccessDecisionManager.html[`AccessDecisionManager`] and {security-api-url}org/springframework/security/access/intercept/AfterInvocationManager.html[`AfterInvocationManager`].
458
+
The difference is that `AuthorizationManager<MethodInvocation>` replaces `AccessDecisionManager` and `AuthorizationManager<MethodInvocationResult>` replaces `AfterInvocationManager`.
459
+
460
+
Given that, <<_i_use_a_custom_accessdecisionvoter,the same rules apply for adaptation>>, where the goal this time is to implement `AuthorizationManager<MethodInvocationResult>` instead of `AuthorizationManager<MethodInvocation>` and use `AuthorizationManagerAfterMethodInterceptor` instead of `AuthorizationManagerBeforeMethodInterceptor`.
==== Check for ``AnnotationConfigurationException``s
372
464
@@ -1099,6 +1191,215 @@ http {
1099
1191
----
1100
1192
====
1101
1193
1194
+
==== Replace any custom filter-security ``AccessDecisionManager``s
1195
+
1196
+
Your application may have a custom {security-api-url}org/springframework/security/access/AccessDecisionManager.html[`AccessDecisionManager`] or {security-api-url}org/springframework/security/access/AccessDecisionVoter.html[`AccessDecisionVoter`] arrangement.
1197
+
The preparation strategy will depend on your reason for each arrangement.
1198
+
Read on to find the best match for your situation.
1199
+
1200
+
===== I use `UnanimousBased`
1201
+
1202
+
If your application uses {security-api-url}org/springframework/security/access/vote/UnanimousBased.html[`UnanimousBased`], you should first adapt or replace any ``AccessDecisionVoter``s and then you can construct an `AuthorizationManager` like so:
`authorizeHttpRequests` is designed so that you can apply a custom `AuthorizationManager` to any url pattern.
1274
+
See xref:servlet/authorization/authorize-http-requests.adoc#custom-authorization-manager[the reference] for more details.
1275
+
====
1276
+
1277
+
===== I use `AffirmativeBased`
1278
+
1279
+
If your application uses {security-api-url}org/springframework/security/access/vote/AffirmativeBased.html[`AffirmativeBased`], then you can construct an equivalent {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`], like so:
`authorizeHttpRequests` is designed so that you can apply a custom `AuthorizationManager` to any url pattern.
1351
+
See xref:servlet/authorization/authorize-http-requests.adoc#custom-authorization-manager[the reference] for more details.
1352
+
====
1353
+
1354
+
===== I use `ConsensusBased`
1355
+
1356
+
There is no framework-provided equivalent for {security-api-url}org/springframework/security/access/vote/ConsensusBased.html[`ConsensusBased`].
1357
+
In that case, please implement a composite {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] that takes the set of delegate ``AuthorizationManager``s into account.
1358
+
1359
+
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/authorize-http-requests.adoc#custom-authorization-manager[adding a custom `AuthorizationManager`].
1360
+
1361
+
===== I use a custom `AccessDecisionVoter`
1362
+
1363
+
You should either change the class to implement {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] or create an adapter.
1364
+
1365
+
1366
+
Without knowing what your custom voter is doing, it is impossible to recommend a general-purpose solution.
1367
+
By way of example, though, here is what adapting {security-api-url}org/springframework/security/access/SecurityMetadataSource.html[`SecurityMetadataSource`] and {security-api-url}org/springframework/security/access/AccessDecisionVoter.html[`AccessDecisionVoter`] for `anyRequest().authenticated()` would look like:
1368
+
1369
+
====
1370
+
.Java
1371
+
[source,java,role="primary"]
1372
+
----
1373
+
public final class AnyRequestAuthenticatedAuthorizationManagerAdapter implements AuthorizationManager<RequestAuthorizationContext> {
1374
+
private final SecurityMetadataSource metadata;
1375
+
private final AccessDecisionVoter voter;
1376
+
1377
+
public PreAuthorizeAuthorizationManagerAdapter(SecurityExpressionHandler expressionHandler) {
int decision = this.voter.vote(authentication.get(), invocation, attributes);
1389
+
if (decision == ACCESS_GRANTED) {
1390
+
return new AuthorizationDecision(true);
1391
+
}
1392
+
if (decision == ACCESS_DENIED) {
1393
+
return new AuthorizationDecision(false);
1394
+
}
1395
+
return null; // abstain
1396
+
}
1397
+
}
1398
+
----
1399
+
====
1400
+
1401
+
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/authorize-http-requests.adoc#custom-authorization-manager[adding a custom `AuthorizationManager`].
You can also wire xref:servlet/authorization/architecture.adoc#authz-custom-authorization-manager[your own custom authorization managers] for any request matcher.
133
133
134
+
[[custom-authorization-manager]]
134
135
Here is an example of mapping a custom authorization manager to the `my/authorized/endpoint`:
0 commit comments