Esempio n. 1
0
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, string resource)
        {
            var roles = ((ClaimsIdentity)context.User.Identity).Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role);

            if (roles != null)
            {
                var listRole      = roles.Value.Split(";");
                var hasPermission = await _functionService.CheckPermission(resource, requirement.Name, listRole);

                if (hasPermission || listRole.Contains(CommonConstants.Admin))
                {
                    context.Succeed(requirement);
                }
                else
                {
                    context.Fail();
                }
            }
            else
            {
                context.Fail();
            }
        }