Beispiel #1
0
        public void OnActionExecuting(ActionExecutingContext actionContext)
        {
            var claimRequirementAttributes = actionContext.ActionDescriptor.FilterDescriptors.Select(x => x.Filter).OfType <ClaimRequirementAttribute>();

            //not equals null just because...not sure that would ever happen
            foreach (var claimRequirementAttribute in claimRequirementAttributes.Where(a => a != null))
            {
                var hasClaim = false;
                try {
                    hasClaim = this.MembershipService.HasClaim(claimRequirementAttribute.Claim);
                } catch (Exception ex) {
                    return;
                }
                if (hasClaim)
                {
                    continue;
                }
                var errorMessage2 = HttpErrorMessage.CreateUnauthorized(this.HostingEnvironment, Messages.SecurityFilter_AccessDenied);
                actionContext.Result = new JsonResult(errorMessage2);
                break;
            }
        }
Beispiel #2
0
 public static HttpErrorMessage CreateUnauthorized(IHostingEnvironment env, string msg)
 {
     return(HttpErrorMessage.Create(env, HttpStatusCode.Forbidden, Urls.UnauthorizedUrl, msg));
 }
Beispiel #3
0
 public static HttpErrorMessage CreateError(IHostingEnvironment env, string msg)
 {
     return(HttpErrorMessage.Create(env, HttpStatusCode.InternalServerError, Urls.Error, msg));
 }