Aspectacular.AuthorizationDemandAttribute.IsAuthorized C# (CSharp) Method

IsAuthorized() public method

public IsAuthorized ( ) : bool
return bool
        public bool IsAuthorized()
        {
            if(DemandedClaims.IsNullOrEmpty())
                return true;

            return this.IsAuthorizedInternal();
        }

Usage Example

        protected void EnsureAuthorization()
        {
            AuthorizationDemandAttribute claimDemandAttrib = this.Proxy.InterceptedCallMetaData.GetMethodOrClassAttribute <AuthorizationDemandAttribute>();

            if (claimDemandAttrib == null)
            {
                return;
            }

            this.LogInformationWithKey("Demanded claims/roles", "{0}: {1}",
                                       claimDemandAttrib.DemandAny ? "ANY" : "ALL",
                                       string.Join(", ", claimDemandAttrib.DemandedClaims)
                                       );

            if (claimDemandAttrib.IsAuthorized())
            {
                return;
            }

            this.Log(EntryType.Warning, "Authorized", false.ToString());

            string errorMsg = string.Format("User \"{0}\" is not authorized to call this function.", claimDemandAttrib.Identity.Name);

            this.Log(EntryType.Warning, "Authorization Failed", errorMsg);

            this.ThrowAuthorizationException(errorMsg);
        }