From ac7f726a2403b56ef89cc53971b64a5059b5790e Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 31 Oct 2022 15:46:11 -0600 Subject: [PATCH] Add RunAsManager Preparation Steps Closes gh-11337 --- docs/modules/ROOT/pages/migration.adoc | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/modules/ROOT/pages/migration.adoc b/docs/modules/ROOT/pages/migration.adoc index 9ce5a44c44..a6b81413d9 100644 --- a/docs/modules/ROOT/pages/migration.adoc +++ b/docs/modules/ROOT/pages/migration.adoc @@ -459,6 +459,38 @@ The difference is that `AuthorizationManager` replaces `Access Given that, <<_i_use_a_custom_accessdecisionvoter,the same rules apply for adaptation>>, where the goal this time is to implement `AuthorizationManager` instead of `AuthorizationManager` and use `AuthorizationManagerAfterMethodInterceptor` instead of `AuthorizationManagerBeforeMethodInterceptor`. +===== I use `RunAsManager` + +There is currently https://github.com/spring-projects/spring-security/issues/11331[no replacement for `RunAsManager`] though one is being considered. + +It is quite straightforward to adapt a `RunAsManager`, though, to the `AuthorizationManager` API, if needed. + +Here is some pseudocode to get you started: + +==== +.Java +[source,java,role="primary"] +---- +public final class RunAsAuthorizationManagerAdapter implements AuthorizationManager { + private final RunAsManager runAs = new RunAsManagerImpl(); + private final SecurityMetadataSource metadata; + private final AuthorizationManager authorization; + + // ... constructor + + public AuthorizationDecision check(Supplier authentication, T object) { + Supplier wrapped = (auth) -> { + List attributes = this.metadata.getAttributes(object); + return this.runAs.buildRunAs(auth, object, attributes); + }; + return this.authorization.check(wrapped, object); + } +} +---- +==== + +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`]. + [[servlet-check-for-annotationconfigurationexceptions]] ==== Check for ``AnnotationConfigurationException``s