public static AuthorizationPolicy Combine(AuthorizationOptions options, IEnumerable <IAuthorizeData> attributes)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (attributes == null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }

            var policyBuilder = new AuthorizationPolicyBuilder();
            var any           = false;

            foreach (var authorizeAttribute in attributes.OfType <AuthorizeAttribute>())
            {
                any = true;
                var useDefaultPolicy = true;
                if (!string.IsNullOrWhiteSpace(authorizeAttribute.Policy))
                {
                    var policy = options.GetPolicy(authorizeAttribute.Policy);
                    if (policy == null)
                    {
                        throw new InvalidOperationException(Resources.FormatException_AuthorizationPolicyNotFound(authorizeAttribute.Policy));
                    }
                    policyBuilder.Combine(policy);
                    useDefaultPolicy = false;
                }
                var rolesSplit = authorizeAttribute.Roles?.Split(',');
                if (rolesSplit != null && rolesSplit.Any())
                {
                    policyBuilder.RequireRole(rolesSplit);
                    useDefaultPolicy = false;
                }
                var authTypesSplit = authorizeAttribute.ActiveAuthenticationSchemes?.Split(',');
                if (authTypesSplit != null && authTypesSplit.Any())
                {
                    foreach (var authType in authTypesSplit)
                    {
                        policyBuilder.AuthenticationSchemes.Add(authType);
                    }
                }
                if (useDefaultPolicy)
                {
                    policyBuilder.Combine(options.DefaultPolicy);
                }
            }
            return(any ? policyBuilder.Build() : null);
        }
 // TODO: Add unit tests
 public static AuthorizationPolicy Combine([NotNull] IEnumerable<AuthorizationPolicy> policies)
 {
     var builder = new AuthorizationPolicyBuilder();
     foreach (var policy in policies)
     {
         builder.Combine(policy);
     }
     return builder.Build();
 }
        public static AuthorizationPolicy Combine([NotNull] IEnumerable <AuthorizationPolicy> policies)
        {
            var builder = new AuthorizationPolicyBuilder();

            foreach (var policy in policies)
            {
                builder.Combine(policy);
            }
            return(builder.Build());
        }
 public static AuthorizationPolicy Combine([NotNull] AuthorizationOptions options, [NotNull] IEnumerable<AuthorizeAttribute> attributes)
 {
     var policyBuilder = new AuthorizationPolicyBuilder();
     var any = false;
     foreach (var authorizeAttribute in attributes.OfType<AuthorizeAttribute>())
     {
         any = true;
         var useDefaultPolicy = true;
         if (!string.IsNullOrWhiteSpace(authorizeAttribute.Policy))
         {
             var policy = options.GetPolicy(authorizeAttribute.Policy);
             if (policy == null)
             {
                 throw new InvalidOperationException(Resources.FormatException_AuthorizationPolicyNotFound(authorizeAttribute.Policy));
             }
             policyBuilder.Combine(policy);
             useDefaultPolicy = false;
         }
         var rolesSplit = authorizeAttribute.Roles?.Split(',');
         if (rolesSplit != null && rolesSplit.Any())
         {
             policyBuilder.RequireRole(rolesSplit);
             useDefaultPolicy = false;
         }
         var authTypesSplit = authorizeAttribute.ActiveAuthenticationSchemes?.Split(',');
         if (authTypesSplit != null && authTypesSplit.Any())
         {
             foreach (var authType in authTypesSplit)
             {
                 policyBuilder.ActiveAuthenticationSchemes.Add(authType);
             }
         }
         if (useDefaultPolicy)
         {
             policyBuilder.Combine(options.DefaultPolicy);
         }
     }
     return any ? policyBuilder.Build() : null;
 }
        public static AuthorizationPolicy Combine(IEnumerable<AuthorizationPolicy> policies)
        {
            if (policies == null)
            {
                throw new ArgumentNullException(nameof(policies));
            }

            var builder = new AuthorizationPolicyBuilder();
            foreach (var policy in policies)
            {
                builder.Combine(policy);
            }
            return builder.Build();
        }
        public static AuthorizationPolicy Combine(IEnumerable <AuthorizationPolicy> policies)
        {
            if (policies == null)
            {
                throw new ArgumentNullException(nameof(policies));
            }

            var builder = new AuthorizationPolicyBuilder();

            foreach (var policy in policies)
            {
                builder.Combine(policy);
            }
            return(builder.Build());
        }
        public static AuthorizationPolicy Combine([NotNull] AuthorizationOptions options, [NotNull] IEnumerable <AuthorizeAttribute> attributes)
        {
            var  policyBuilder = new AuthorizationPolicyBuilder();
            bool any           = false;

            foreach (var authorizeAttribute in attributes.OfType <AuthorizeAttribute>())
            {
                any = true;
                var requireAnyAuthenticated = true;
                if (!string.IsNullOrWhiteSpace(authorizeAttribute.Policy))
                {
                    var policy = options.GetPolicy(authorizeAttribute.Policy);
                    if (policy == null)
                    {
                        throw new InvalidOperationException(Resources.FormatException_AuthorizationPolicyNotFound(authorizeAttribute.Policy));
                    }
                    policyBuilder.Combine(policy);
                    requireAnyAuthenticated = false;
                }
                var rolesSplit = authorizeAttribute.Roles?.Split(',');
                if (rolesSplit != null && rolesSplit.Any())
                {
                    policyBuilder.RequireRole(rolesSplit);
                    requireAnyAuthenticated = false;
                }
                string[] authTypesSplit = authorizeAttribute.ActiveAuthenticationSchemes?.Split(',');
                if (authTypesSplit != null && authTypesSplit.Any())
                {
                    foreach (var authType in authTypesSplit)
                    {
                        policyBuilder.ActiveAuthenticationSchemes.Add(authType);
                    }
                }
                if (requireAnyAuthenticated)
                {
                    policyBuilder.RequireAuthenticatedUser();
                }
            }
            return(any ? policyBuilder.Build() : null);
        }