Exemplo n.º 1
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
 public PermissibleValuesControllerDescriptor(AccessRuleMap accessRuleMap, IPermissibleValuesDescriptor permissibleValuesDescriptor, Type permissibleValuesProviderType, IComponentContext context)
 {
     _permissibleValuesProviderType = permissibleValuesProviderType;
     _context    = context;
     AccessRules = accessRuleMap;
     PermissibleValuesDescriptor = permissibleValuesDescriptor;
     _permissibleValuesProvider  = new Lazy <IPermissibleValuesProvider <TEntity, TEnum> >(PermissibleValuesProviderFactory);
 }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, Type resource)
        {
            AccessRuleMap accessRules = null;

            if (_resourcePointControllerRegistry.HasEntity(resource.Name))
            {
                accessRules = _resourcePointControllerRegistry[resource.Name].AccessRules;
            }
            else

            if (_permissibleValuesControllerRegistry.HasEntity(resource.Name))
            {
                accessRules = _permissibleValuesControllerRegistry[resource.Name].AccessRules;
            }


            var roles = _currentIdentityInfoProvider.GetRoles();

            if (requirement.Name == CrudOperations.Read.Name)
            {
                if (accessRules.CanRead(roles))
                {
                    context.Succeed(requirement);
                }
            }
            else
            {
                if (accessRules.CanModify(roles))
                {
                    context.Succeed(requirement);
                }
            }


            return(Task.CompletedTask);
        }