Skip to content

Commit ac7f726

Browse files
committed
Add RunAsManager Preparation Steps
Closes gh-11337
1 parent c5badbc commit ac7f726

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/modules/ROOT/pages/migration.adoc

+32
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,38 @@ The difference is that `AuthorizationManager<MethodInvocation>` replaces `Access
459459

460460
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`.
461461

462+
===== I use `RunAsManager`
463+
464+
There is currently https://github.com/spring-projects/spring-security/issues/11331[no replacement for `RunAsManager`] though one is being considered.
465+
466+
It is quite straightforward to adapt a `RunAsManager`, though, to the `AuthorizationManager` API, if needed.
467+
468+
Here is some pseudocode to get you started:
469+
470+
====
471+
.Java
472+
[source,java,role="primary"]
473+
----
474+
public final class RunAsAuthorizationManagerAdapter<T> implements AuthorizationManager<T> {
475+
private final RunAsManager runAs = new RunAsManagerImpl();
476+
private final SecurityMetadataSource metadata;
477+
private final AuthorizationManager<T> authorization;
478+
479+
// ... constructor
480+
481+
public AuthorizationDecision check(Supplier<Authentication> authentication, T object) {
482+
Supplier<Authentication> wrapped = (auth) -> {
483+
List<ConfigAttribute> attributes = this.metadata.getAttributes(object);
484+
return this.runAs.buildRunAs(auth, object, attributes);
485+
};
486+
return this.authorization.check(wrapped, object);
487+
}
488+
}
489+
----
490+
====
491+
492+
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`].
493+
462494
[[servlet-check-for-annotationconfigurationexceptions]]
463495
==== Check for ``AnnotationConfigurationException``s
464496

0 commit comments

Comments
 (0)