Skip to content

Simplify AuthorizationManager composition #11625

@jzheaux

Description

@jzheaux

To compose two authorization managers, some boilerplate is necessary. For example, to achieve a logical "or" between two authorization managers, they can be composed like so:

(authentication, object) -> {
    AuthorizationDecision decision = this.first.check(authentication, object);
    if (decision != null && decision.isGranted()) {
        return decision;
    }
    return this.second.check(authentication, object);
}

It would be nice to have an easy way to compose authorization managers in an "any" or "all" fashion, similar to the AffirmativeBased and UnanimousBased access decision managers.

One way to do this would be to introduce a static class AuthorizationManagers with convenience methods like so:

public static <T> AuthorizationManager<T> any(AuthorizationManager<T>... authorizationManagers);

public static <T> AuthorizationManager<T> all(AuthorizationManager<T>... authorizationManagers);

Then, the above code could be simplified to:

AuthorizationManagers.any(this.first, this.second);

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-coretype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions