Skip to content

Add hasScope for authorization rules #13754

@jzheaux

Description

@jzheaux

AuthorizationManager makes the following possible in the DSL:

http
    .authorizeHttpRequests((authorize) -> authorize
        .anyRequest().access(hasRole("USER"))
    )

It would be nice to be able to do the same with scopes, like so:

http
    .authorizeHttpRequests((authorize) -> authorize
        .anyRequest().access(hasScope("resource:read"))
    )

This could be done in a static factory class like OAuth2AuthorizationManagers in oauth2-core. It could have hasScope and hasAnyScope. They might be implemented by delegating to AuthorityAuthorizationManager like this:

public static <T> AuthorityAuthorizationManager<T> hasScope(String scope) {
    return AuthorityAuthorizationManager.hasAuthority("SCOPE_" + scope);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions