Example #1
0
        /// <summary>
        /// Authorize exposures
        /// </summary>
        /// <param name="role"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        public ITypeSetExposureConfiguration Authorize(string role = null, string policy = null)
        {
            IMethodAuthorization authorize = null;

            if (role != null)
            {
                authorize = new UserRoleAuthorization(role);
            }
            else if (policy != null)
            {
                authorize = new UserPolicyAuthorization(policy);
            }
            else
            {
                authorize = new UserAuthenticatedAuthorization();
            }

            _authorizations = _authorizations.Add(t => new[] { authorize });

            return(this);
        }
Example #2
0
        /// <summary>
        /// Set default Authorize
        /// </summary>
        /// <param name="role"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        public IApiConfiguration Authorize(string role = null, string policy = null)
        {
            IMethodAuthorization authorization = null;

            if (!string.IsNullOrEmpty(role))
            {
                authorization = new UserRoleAuthorization(role);
            }
            else if (!string.IsNullOrEmpty(policy))
            {
                authorization = new UserPolicyAuthorization(policy);
            }
            else
            {
                authorization = new UserAuthenticatedAuthorization();
            }
            var array = new[] { authorization };

            _authorizations = _authorizations.Add(t => array);

            return(this);
        }