public ActionResult AccessControlPartial(bool?GetInactive)
        {
            var accessControls = (GetInactive.GetValueOrDefault()) ? _AccessControlService.GetAll() : _AccessControlService.GetAllActive().OrderBy(x => x.LastUpdated);

            ViewBag.GetInactive = GetInactive;
            return(PartialView("AccessControlPartial", accessControls.ToList()));
        }
Exemple #2
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ServerAuthorizationRequirement requirement)
        {
            if (!context.User.HasClaim(c => c.Type == ClaimTypes.Email))
            {
                return(Task.CompletedTask);
            }

            var emailAddress = context.User.FindFirst(
                c => c.Type == ClaimTypes.Email).Value;

            var regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            var match = regex.Match(emailAddress);

            if (match.Success)
            {
                _logger.LogInformation("Email Address of JWT payload:" + emailAddress);

                var vmOrgData = _accessControlService.GetAll(emailAddress);

                //Compare AccessRequired to user permissions from db.
                if (vmOrgData.Permissions.Exists(p => p.PermissionCode.Equals(requirement.AccessRequired)))
                {
                    if (context.Resource is Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext mvcContext)
                    {
                        mvcContext.HttpContext.Items[AuthKeys.OrganisationKey] = vmOrgData.OrganisationId;
                        mvcContext.HttpContext.Items[AuthKeys.ScenarioIdsKey]  = vmOrgData.ScenarioIds;
                        mvcContext.HttpContext.Items[AuthKeys.UserKey]         = vmOrgData.UserId;
                        context.Succeed(requirement);
                    }
                }
            }

            return(Task.CompletedTask);
        }