public WikiAuthorizationRule(AuthorizationRule rule)
        {
            if (rule.Scope != AuthorizationRuleScope.Wiki)
            {
                throw new ArgumentException("Rule must be a wiki-level rule.");
            }

            _action = rule.Action;
            _polarity = rule.Polarity;
            _who = rule.Who;
        }
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            if (!string.IsNullOrEmpty(reader.NamespaceURI))
            {
                return;
            }

            string type = reader.GetAttribute("Type");

            if (type == StringLiterals.Allow)
            {
                _polarity = AuthorizationRulePolarity.Allow;
            }
            else if (type == StringLiterals.Deny)
            {
                _polarity = AuthorizationRulePolarity.Deny;
            }
            else
            {
                throw new NotSupportedException("Unsupported or missing rule type: " + ((type == null) ? "<<null>>" : type));
            }

            _action = (SecurableAction) Enum.Parse(typeof(SecurableAction), reader.GetAttribute("Action"));
            _who = AuthorizationRuleWho.Parse(reader.GetAttribute("Principal"));
            reader.Read();
        }
        public static bool TryParse(string input, out AuthorizationRuleWho who)
        {
            who = null;
            AuthorizationRuleWhoType whoType;
            string principal = null;
            if (input.StartsWith(StringLiterals.UserPrefix, StringComparison.InvariantCultureIgnoreCase))
            {
                whoType = AuthorizationRuleWhoType.User;
                principal = input.Substring(StringLiterals.UserPrefix.Length);
            }
            else if (input.StartsWith(StringLiterals.RolePrefix, StringComparison.InvariantCultureIgnoreCase))
            {
                whoType = AuthorizationRuleWhoType.Role;
                principal = input.Substring(StringLiterals.RolePrefix.Length);
            }
            else if (input.Equals(StringLiterals.Authenticated, StringComparison.InvariantCultureIgnoreCase))
            {
                whoType = AuthorizationRuleWhoType.GenericAuthenticated;
            }
            else if (input.Equals(StringLiterals.Anonymous, StringComparison.InvariantCultureIgnoreCase))
            {
                whoType = AuthorizationRuleWhoType.GenericAnonymous;
            }
            else if (input.Equals(StringLiterals.All, StringComparison.InvariantCultureIgnoreCase))
            {
                whoType = AuthorizationRuleWhoType.GenericAll;
            }
            else
            {
                return false;
            }

            who = new AuthorizationRuleWho(whoType, principal);
            return true;
        }
Esempio n. 4
0
        private static bool IsValidCombination(AuthorizationRuleWho who, AuthorizationRulePolarity what, AuthorizationRuleScope where,
            SecurableAction permission)
        {
            if ((where == AuthorizationRuleScope.Topic) && (permission == SecurableAction.ManageNamespace))
            {
                return false;
            }

            return true;
        }