NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.16k stars 1.47k forks source link

Added Module extension RequiresRoles(string[] roles) and ... #2982

Closed jetic83 closed 4 years ago

jetic83 commented 4 years ago

... RequiresAnyRole(string[] roles)

This relates directly to #2981 and a bit also to #1190

Prerequisites

Description

As the ClaimsPrincipal offers a function user.HasClaim, Nancy provides a hook to check if a claim is present (RequiresClaims, RequiresAnyClaim). However, this did not exist for roles: While the ClaimsPrincipal offers user.IsInRole(), Nancy does not leverage that for modules.

This PR extends the Module hooks with the two documented functions RequiresAnyRole(string[] requiredRoles) and RequiresRoles(string[] requiredRoles).

This facilitates the check for roles when entering routes drastically.

Tests are also included in this PR.

dnfclas commented 4 years ago

CLA assistant check
All CLA requirements met.