Skip to content

Add hasScope as a valid SpEL expression to PreAuthorize, etc. #18013

@kistlers

Description

@kistlers

Expected Behavior

In a similar fashion to the added hasScope for authorization rules (added with #13754), I would like to use hasScope(scope) in SpEL expressions in @PreAuthorize, i.e.:

@PreAuthorize("hasScope('read'")

Current Behavior

This can already be achieved using hasAuthority:

@PreAuthorize("hasAuthority('SCOPE_read'")

Evidently, not a big issue. But I'd like to add that hasRole also exists:

private String defaultRolePrefix = "ROLE_";

@Override
public final boolean hasAnyRole(String... roles) {
    return hasAnyAuthorityName(this.defaultRolePrefix, roles);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions