Example #1
0
        /// <summary>
        ///     Validates application user access rights to execute the function.
        /// </summary>
        /// <param name="type">The access type being validated.</param>
        /// <param name="loginId">The login ID of application user making the request.</param>
        /// <param name="catalog">The name of the database on which policy is being validated on.</param>
        /// <param name="noException">
        ///     If this is switched off, UnauthorizedException is not thrown even when the caller does not
        ///     have access rights to this function.
        /// </param>
        public void Validate(AccessTypeEnum type, long loginId, string catalog, bool noException)
        {
            var policy = new PolicyValidator
            {
                ObjectNamespace = this._ObjectNamespace,
                ObjectName = this._ObjectName,
                LoginId = loginId,
                Catalog = catalog,
                AccessType = type
            };

            policy.Validate();
            this.HasAccess = policy.HasAccess;

            this.Validated = true;

            if (this.HasAccess)
            {
                return;
            }

            if (!noException)
            {
                throw new UnauthorizedException("Access is denied.");
            }
        }
Example #2
0
        public List <Claim> GetClaimType(AccessTypeEnum Permission)
        {
            List <Claim> claims = new List <Claim>();

            switch (Permission)
            {
            case AccessTypeEnum.Administration:
                claims.Add(new Claim("Administration", "true"));
                claims.Add(new Claim("DatabaseAdministration", "true"));
                claims.Add(new Claim("ReportsAdministration", "true"));
                claims.Add(new Claim("Read", "true"));
                break;

            case AccessTypeEnum.DatabaseAdministration:
                claims.Add(new Claim("DatabaseAdministration", "true"));
                claims.Add(new Claim("Read", "true"));
                break;

            case AccessTypeEnum.ReportsAdministration:
                claims.Add(new Claim("ReportsAdministration", "true"));
                claims.Add(new Claim("Read", "true"));
                break;

            case AccessTypeEnum.Read:
                claims.Add(new Claim("Read", "true"));
                break;
            }

            return(claims);
        }
Example #3
0
        /// <summary>
        ///     Validates application user access rights to execute the function.
        /// </summary>
        /// <param name="type">The access type being validated.</param>
        /// <param name="loginId">The login ID of application user making the request.</param>
        /// <param name="catalog">The name of the database on which policy is being validated on.</param>
        /// <param name="noException">
        ///     If this is switched off, UnauthorizedException is not thrown even when the caller does not
        ///     have access rights to this function.
        /// </param>
        public void Validate(AccessTypeEnum type, long loginId, string catalog, bool noException)
        {
            PolicyValidator policy = new PolicyValidator
            {
                ObjectNamespace = this._ObjectNamespace,
                ObjectName      = this._ObjectName,
                LoginId         = loginId,
                Catalog         = catalog,
                AccessType      = type
            };

            policy.Validate();
            this.HasAccess = policy.HasAccess;

            this.Validated = true;


            if (this.HasAccess)
            {
                return;
            }

            if (!noException)
            {
                throw new UnauthorizedException("Access is denied.");
            }
        }
Example #4
0
        /// <summary>
        ///     Validates application user access rights to execute the function.
        /// </summary>
        /// <param name="type">The access type being validated.</param>
        /// <param name="loginId">The login ID of application user making the request.</param>
        /// <param name="database">The name of the database on which policy is being validated on.</param>
        /// <param name="noException">
        ///     If this is switched off, UnauthorizedException is not thrown even when the caller does not
        ///     have access rights to this function.
        /// </param>
        public async Task ValidateAsync(AccessTypeEnum type, long loginId, string database, bool noException)
        {
            var policy = new PolicyValidator
            {
                ObjectNamespace = this._ObjectNamespace,
                ObjectName      = this._ObjectName,
                LoginId         = loginId,
                Database        = database,
                AccessType      = type
            };

            await policy.ValidateAsync().ConfigureAwait(false);

            this.HasAccess = policy.HasAccess;

            this.Validated = true;


            if (this.HasAccess)
            {
                return;
            }

            if (!noException)
            {
                throw new UnauthorizedException("Access is denied.");
            }
        }
Example #5
0
        /// <summary>
        ///     Validates application user access rights to execute the function.
        /// </summary>
        /// <param name="type">The access type being validated.</param>
        /// <param name="loginId">The login ID of application user making the request.</param>
        /// <param name="database">The name of the database on which policy is being validated on.</param>
        /// <param name="noException">
        ///     If this is switched off, UnauthorizedException is not thrown even when the caller does not
        ///     have access rights to this function.
        /// </param>
        public async Task ValidateAsync(AccessTypeEnum type, long loginId, string database, bool noException)
        {
            var policy = new PolicyValidator
                         {
                             ObjectNamespace = this._ObjectNamespace,
                             ObjectName = this._ObjectName,
                             LoginId = loginId,
                             Database = database,
                             AccessType = type
                         };

            await policy.ValidateAsync().ConfigureAwait(false);
            this.HasAccess = policy.HasAccess;

            this.Validated = true;


            if(this.HasAccess)
            {
                return;
            }

            if(!noException)
            {
                throw new UnauthorizedException("Access is denied.");
            }
        }
Example #6
0
        public static bool HasAccess(string pocoNamespace, AccessTypeEnum accessTypeEnum, int userId)
        {
            int          accessType = (int)accessTypeEnum;
            const string sql        = "SELECT * FROM policy.has_access(@0, @1, @2);";

            //Todo
            return(true);
        }
        protected override void MapEntityToCustomProperties(IENTBaseEntity entity)
        {
            ENTCapability capability = (ENTCapability)entity;

            ID             = capability.ENTCapabilityId;
            CapabilityName = capability.CapabilityName;
            MenuItemId     = capability.ENTMenuItemId;
            AccessType     = (AccessTypeEnum)capability.AccessType;
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OnDemandPromotion" /> class.
 /// </summary>
 /// <param name="accessType">The type of access that the promotion grants.  Option descriptions:  * &#x60;default&#x60; - The promotion grants discounts on existing product offerings.  * &#x60;vip&#x60; - The promotion grants free access to On Demand content before it is released or to access types that aren&#39;t part of the existing product offerings.  (required).</param>
 /// <param name="discountType">The type of discount that the promotion provides.  Option descriptions:  * &#x60;dollars&#x60; - The promotion discounts a fixed amount from the full purchase price.  * &#x60;free&#x60; - The promotion discounts the full purchase price. When **access_type** is &#x60;vip&#x60;, **discount_type** is always &#x60;free&#x60;.  * &#x60;percent&#x60; - The promotion discounts a percentage of the full purchase price.  (required).</param>
 /// <param name="download">Whether the promotion grants download access to On Demand content. (required).</param>
 /// <param name="label">The prefix string for batch codes, or the null value for single codes. (required).</param>
 /// <param name="metadata">metadata (required).</param>
 /// <param name="percentOff">When **discount_type** is &#x60;percent&#x60;, the percentage amount that is deducted from the product price. (required).</param>
 /// <param name="productType">The type of product to which the promotion can be applied. Only the &#x60;buy&#x60; and &#x60;rent&#x60; options are available when **access_type** is &#x60;vip&#x60;.  Option descriptions:  * &#x60;any&#x60; - The promotion can be applied to any product.  * &#x60;buy&#x60; - The promotion can be applied to a buyable single video.  * &#x60;buy_episode&#x60; - The promotion can be applied to a buyable single episode.  * &#x60;rent&#x60; - The promotion can be applied to a rentable single video.  * &#x60;rent_episode&#x60; - The promotion can be applied to a rentable single episode.  * &#x60;subscribe&#x60; - The promotion can be applied to a subscription.  (required).</param>
 /// <param name="streamPeriod">The amount of time that the user has access to the On Demand content after redeeming a promo code.  Option descriptions:  * &#x60;1_week&#x60; - Access lasts for one week.  * &#x60;1_year&#x60; - Access lasts for one year.  * &#x60;24_hour&#x60; - Access lasts for 24 hours.  * &#x60;30_days&#x60; - Access lasts for 30 days.  * &#x60;3_month&#x60; - Access lasts for three months.  * &#x60;48_hour&#x60; - Access lasts for 48 hours.  * &#x60;6_month&#x60; - Access lasts for six months.  * &#x60;72_hour&#x60; - Access lasts for 72 hours.  (required).</param>
 /// <param name="total">When **type** is &#x60;single&#x60;, the total number of times that the promotion can be used. When **type** is &#x60;batch&#x60; or &#x60;batch_prefix&#x60;, the total number of promo codes that have been generated. (required).</param>
 /// <param name="type">The way in which the promotion generates promo codes.  Option descriptions:  * &#x60;batch&#x60; - The promotion provides a unique promo code for each user.  * &#x60;batch_prefix&#x60; - Like &#x60;batch&#x60;, except that all codes have a similar prefix string. This option is deprecated, yet it may still appear for some users.  * &#x60;single&#x60; - The promotion provides a single promo code for all users.  (required).</param>
 /// <param name="uri">The promotion&#39;s canonical relative URI. (required).</param>
 public OnDemandPromotion(AccessTypeEnum accessType = default(AccessTypeEnum), DiscountTypeEnum discountType = default(DiscountTypeEnum), bool download = default(bool), string label = default(string), OnDemandPromotionMetadata metadata = default(OnDemandPromotionMetadata), decimal percentOff = default(decimal), ProductTypeEnum productType = default(ProductTypeEnum), StreamPeriodEnum streamPeriod = default(StreamPeriodEnum), decimal total = default(decimal), TypeEnum type = default(TypeEnum), string uri = default(string))
 {
     this.AccessType   = accessType;
     this.DiscountType = discountType;
     this.Download     = download;
     // to ensure "label" is required (not null)
     this.Label = label ?? throw new ArgumentNullException("label is a required property for OnDemandPromotion and cannot be null");
     // to ensure "metadata" is required (not null)
     this.Metadata     = metadata ?? throw new ArgumentNullException("metadata is a required property for OnDemandPromotion and cannot be null");
     this.PercentOff   = percentOff;
     this.ProductType  = productType;
     this.StreamPeriod = streamPeriod;
     this.Total        = total;
     this.Type         = type;
     // to ensure "uri" is required (not null)
     this.Uri = uri ?? throw new ArgumentNullException("uri is a required property for OnDemandPromotion and cannot be null");
 }
 public AccessPolicyAttribute(string objectNamespace, string objectName, AccessTypeEnum type)
 {
     this.ObjectNamespace = objectNamespace;
     this.ObjectName      = objectName;
     this.Type            = type;
 }