Skip to content

Make the name of the claim for roles configurable#5519

Open
WilliamBZA wants to merge 4 commits into
authfrom
roleclaimconfigurable
Open

Make the name of the claim for roles configurable#5519
WilliamBZA wants to merge 4 commits into
authfrom
roleclaimconfigurable

Conversation

@WilliamBZA
Copy link
Copy Markdown
Member

No description provided.

@WilliamBZA WilliamBZA force-pushed the roleclaimconfigurable branch from a5eff01 to 387a416 Compare June 5, 2026 08:21
The recent refactor moved Authentication.RoleBasedAuthorizationEnabled
to a separate master switch (default false) and made the entire
authorization registration short-circuit when it was off. That left the
permission policy provider unregistered in every default deployment, so
ASP.NET could not resolve the policy names emitted by [Authorize(Policy
= Permissions.X)] attributes — every annotated endpoint returned 500
with "AuthorizationPolicy named '...' was not found", which is what was
timing out the audit acceptance tests at 90s each.

PermissionPolicyProvider already returns allow-all policies for every
known permission when its oidcEnabled flag is false. Registering it
unconditionally and passing RoleBasedAuthorizationEnabled to that flag
gives the right behaviour in all three combinations: RBAC off →
allow-all (controllers reachable, no permission check), RBAC on →
require auth + the permission requirement evaluated by
PermissionVerbHandler. The handler itself remains gated on
RoleBasedAuthorizationEnabled since it has nothing to evaluate when
RBAC is off.
Authentication.RoleBasedAuthorizationEnabled defaults to false, so
without an explicit opt-in the policy provider returns allow-all and
unauthenticated requests reach the controller — breaking every
Should_reject_requests_* test in the three When_authentication_is_enabled
classes. Add WithRoleBasedAuthorizationEnabled() to the test
configuration helper and call it alongside WithAuthenticationEnabled()
in all three OIDC enabled fixtures.
Two settings shifted in the OpenIdConnectSettings serialisation:
RolesClaim moved after the ServicePulse block and its default changed
from "realm_access.roles" to "roles", and the new
RoleBasedAuthorizationEnabled property (default false) was added. Sync
the three approved snapshots so the approval tests reflect the current
shape.
Copy link
Copy Markdown
Member

@ramonsmits ramonsmits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted return statement, as we always need a policy provider due to the Authorize attribute.

All test green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants