Skip to content

Allow extensibility of DefaultAuthorizationService #23143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2020
Merged

Allow extensibility of DefaultAuthorizationService #23143

merged 2 commits into from
Jul 1, 2020

Conversation

hansmbakker
Copy link
Contributor

When only a small behavior change of the DefaultAuthorizationService is wanted, it would be nice if you could override its methods and building upon them rather than having a copy-paste of the class in your codebase.

Inside the override methods in your inherited class you could call the base method to reuse parts of its logic.

Please refer to #23094 for the usecase & details.

Addresses #23094

@@ -77,7 +77,7 @@ public DefaultAuthorizationService(IAuthorizationPolicyProvider policyProvider,
/// A flag indicating whether authorization has succeeded.
/// This value is <value>true</value> when the user fulfills the policy otherwise <value>false</value>.
/// </returns>
public async Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, IEnumerable<IAuthorizationRequirement> requirements)
public virtual async Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, IEnumerable<IAuthorizationRequirement> requirements)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this couldn't use explicit interface implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that way you can only replace the methods instead of building upon them?

When allowing to override, a developer can still call the base method from inside the overridden method to reuse the logic and add own behavior.

@HaoK
Copy link
Member

HaoK commented Jun 30, 2020

hansmbakker and others added 2 commits June 30, 2020 10:19
When only a small behavior change of the `DefaultAuthorizationService` is wanted, it would be nice if you could override its methods and building upon them rather than having a copy-paste of the class in your codebase.

Inside the `override` methods in your inherited class you could call the `base` method to reuse parts of its logic.

Please refer to #23094 for the usecase.
@hansmbakker
Copy link
Contributor Author

@HaoK done

@dnfadmin
Copy link

dnfadmin commented Jun 30, 2020

CLA assistant check
All CLA requirements met.

@HaoK HaoK merged commit 5db8951 into dotnet:master Jul 1, 2020
@HaoK
Copy link
Member

HaoK commented Jul 1, 2020

Thanks @hansmbakker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants