Exemplo n.º 1
0
        public static void Save(object arr)
        {
            int i = 0;
            IEnumerable <Role> iRoleList = RoleList.Where(r => r.Name != System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);

            foreach (object[] item in (object[])arr)
            {
                int j = 0;
                foreach (bool subItem in item)
                {
                    if (subItem != AuthenticationList[i][j])
                    {
                        Role            role            = iRoleList.ElementAt(i);
                        TopicPermission topicPermission = TopicPermissionList[j];
                        if (subItem)
                        {
                            TopicAuthenticationManager.AddPermission(topicPermission, role);
                        }
                        else
                        {
                            TopicAuthenticationManager.RemovePermission(topicPermission, role);
                        }
                    }
                    j++;
                }
                i++;
            }
        }
Exemplo n.º 2
0
        internal static bool GetGrantExpectation(TopicPermission topicPermission, TestIdentity identity, params AuthorizationRule[] rules)
        {
            List<AuthorizationRule> sortedRules = new List<AuthorizationRule>();
            sortedRules.AddRange(rules);
            sortedRules.Sort();

            bool granted = false;
            foreach (AuthorizationRule rule in sortedRules)
            {
                if (DoesRuleApply(rule, identity))
                {
                    if (rule.Polarity == AuthorizationRulePolarity.Allow)
                    {
                        if ((int)topicPermission >= (int)rule.Action)
                        {
                            granted = true;
                        }
                    }
                    else if (rule.Polarity == AuthorizationRulePolarity.Deny)
                    {
                        if ((int)topicPermission <= (int)rule.Action)
                        {
                            granted = false;
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            return granted;
        }
Exemplo n.º 3
0
        public Task DeleteTopicPermissionAsync(TopicPermission topicPermission,
                                               CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.ArgumentNotNull(topicPermission, nameof(topicPermission));

            return(DeleteAsync($"topic-permissions/{topicPermission.Vhost}/{topicPermission.User}", cancellationToken));
        }
        /// <summary>
        ///     Delete a topic permission
        /// </summary>
        /// <param name="source"></param>
        /// <param name="permission">The topic permission to delete</param>
        /// <param name="cancellationToken"></param>
        public static void DeleteTopicPermission(
            [NotNull] this IManagementClient source,
            [NotNull] TopicPermission permission,
            CancellationToken cancellationToken = default
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            source.DeleteTopicPermissionAsync(permission, cancellationToken)
            .GetAwaiter()
            .GetResult();
        }
Exemplo n.º 5
0
        public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
        {
            // If it's not a built-in topic, just pass the question along
            if (!IsBuiltInTopic(topic))
            {
                return Next.HasPermission(topic, permission);
            }

            // Otherwise, if it is a built-in topic, does it exist in the next provider?
            if (Next.TopicExists(topic))
            {
                // If it does, whatever is true here is true there
                return Next.HasPermission(topic, permission);
            }

            if (permission == TopicPermission.Read)
            {
                return true;
            }
            // Otherwise, it's writable only if the next provider is writable as a whole.
            else if (permission == TopicPermission.Edit)
            {
                return !Next.IsReadOnly;
            }

            return false;
        }
 private void AssertHasPermissionFromCache(
     TestParameters<TopicCacheProvider> parameters,
     UnqualifiedTopicName topicName,
     TopicPermission topicPermission,
     string messageTag)
 {
     string messageFormat = "Checking that retrieval comes from cache: {0} {1}";
     parameters.Store.HasPermissionCalled = false;
     bool thirteenthRetrieval = parameters.Provider.HasPermission(topicName, topicPermission);
     Assert.IsFalse(parameters.Store.HasPermissionCalled,
         string.Format(messageFormat, topicPermission, messageTag));
 }
Exemplo n.º 7
0
        public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
        {
            if (!_sqlHelper.TopicExists(Namespace, topic.LocalName))
            {
                // It might seem a little weird to return true if the topic doesn't exist, but
                // basically what we're saying is that there's no reason to deny read/edit
                return true;
            }

            if (permission == TopicPermission.Read)
            {
                return true;
            }
            else if (permission == TopicPermission.Edit)
            {
                return _sqlHelper.IsExistingTopicWritable(Namespace, topic.LocalName);
            }
            else
            {
                throw new ArgumentException("Unrecognized topic permission: " + permission.ToString());
            }
        }
Exemplo n.º 8
0
 public override bool HasPermission(UnqualifiedTopicName topicName, TopicPermission permission)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
 {
     AddDependency(new TopicPermissionsDependency(topic.ResolveRelativeTo(Namespace)));
     return Next.HasPermission(topic, permission);
 }
Exemplo n.º 10
0
        public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
        {
            _hasPermissionCalled = true;

            MockTopic mockTopic = GetTopic(topic, ExistencePolicy.ExistingOnly);
            if (mockTopic == null)
            {
                return true;
            }

            if (permission == TopicPermission.Edit)
            {
                return mockTopic.Latest.CanWrite;
            }
            else if (permission == TopicPermission.Read)
            {
                return mockTopic.Latest.CanRead;
            }
            else
            {
                throw new ArgumentException("Unrecognized TopicPermission " + permission.ToString());
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Answer whether the current user has the given permission for the specified topic.
 /// </summary>
 /// <param name="topic">The topic </param>
 /// <returns>true if the topic exists AND the specified permission is allowed for the current user; else false</returns>
 public virtual bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
 {
     return _next.HasPermission(topic, permission);
 }
Exemplo n.º 12
0
        //public static string ExtractNameFromTopicName(string topicName)
        //{
        //    int p = topicName.IndexOf("(");
        //    if (p == -1)
        //        return topicName;
        //    return topicName.Substring(0, p);
        //}
        //public static string ExtractVersionFromTopicName(string topicName)
        //{
        //    // ab(xyz)
        //    //
        //    int p = topicName.IndexOf("(");
        //    if (p == -1)
        //        return topicName;
        //    int close = topicName.LastIndexOf(")");
        //    return topicName.Substring(p + 1, close - p - 1);
        //}
        /// <summary>
        /// Answer whether a topic exists and is writable
        /// </summary>
        /// <param name="topic">The topic (must directly be in this content base)</param>
        /// <returns>true if the topic exists AND is writable by the current user; else false</returns>
        public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
        {
            throw new NotImplementedException();
            //if (!SqlHelper.TopicExists(Namespace, topic.LocalName, _connectionString))
            //{
            //    return false;
            //}

            //return SqlHelper.IsExistingTopicWritable(Namespace, topic.LocalName, _connectionString);
        }
 public bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
 {
     using (CreateRecursionContext())
     {
         return _next.HasPermission(topic, permission);
     }
 }
Exemplo n.º 14
0
 public abstract bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission);
Exemplo n.º 15
0
        /// <summary>
        /// Answer whether a topic is readable or writable
        /// </summary>
        /// <param name="topic">The topic (must directly be in this content base)</param>
        /// <returns>true is writable by the current user (or does not exist); else false</returns>
        public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
        {
            string path = TopicPath(topic, null);
            if (!FileSystem.FileExists(path))
            {
                // It might seem a little weird to return true if the topic doesn't exist, but
                // basically what we're saying is that there's no reason to deny read/edit.
                return true;
            }

            if (permission == TopicPermission.Edit)
            {
                if (!FileSystem.HasWritePermission(path))
                {
                    return false;
                }
            }
            else if (permission == TopicPermission.Read)
            {
                if (!FileSystem.HasReadPermission(path))
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 16
0
 public bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
 {
     return ContentProviderChain.HasPermission(topic, permission);
 }
Exemplo n.º 17
0
 public override bool HasPermission(UnqualifiedTopicName topic, TopicPermission permission)
 {
     RegisterCall(MethodInfo.GetCurrentMethod());
     throw new NotImplementedException();
 }
 private void AssertDenied(AuthorizationProvider provider, string topic, TopicPermission topicPermission)
 {
     Assert.IsFalse(provider.HasPermission(new UnqualifiedTopicName(topic), topicPermission),
         string.Format("Checking that user is denied permission {0} on topic {1}", topicPermission, topic));
 }