You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
In WebApi 2 we used an AuthorizationFlterAttribute to implement the following permissions based concept:
Each controller action has a permission code associated.
Roles are associated with a set of permissions. This set can change over time.
A user has one or more roles.
Authorization is determined by checking if any of the user's roles is associated with the action's permission code.
This was easy to use by the developer. He/she only had to decorate an action with the corresponding attribute.
It seems the new policy based approach in ASP.NET 5 makes it hard to implement his concept, because there is no way for the Handle method of the AuthorizationHandler to include the permission code in its arguments. The only way I could solve this problem was to create one new policy for each unique permission code. Since there is a large number of actions, I now have to create an equally large number of policies. It would not be a huge change to the infrastructure to be able to attach extra information to the attribute and pass it through to the handler in the AuthorizationContext, or even pass the attribute through itself. For example, the handler code could then look like this:
protected override void Handle(AuthorizationContext context, PermissionRequirement requirement) {
var userRoles = context.User.FindAll(System.Security.Claims.ClaimTypes.Role);
var permissionsAttribute = context.Attribute as PermissionAttribute;
if (permissionsAttribute == null)
return;
if (myPermissionsChecker.RolesHavePermission(userRoles, permissionsAttribute.Permission)) {
context.Succeed(requirement);
}
}
This would only require a single policy, and the developer would not be burdened with having to create a new policy everytime a new controller action is added.