Inheritance: System.Configuration.ConfigurationElement
 public void Set(int index, AuthorizationRule rule)
 {
     if (BaseGet(index) != null)
     {
         BaseRemoveAt(index);
     }
     BaseAdd(index, rule);
 }
Beispiel #2
0
        protected override void Reset(ConfigurationElement parentElement)
        {
            AuthorizationRule r = (AuthorizationRule)parentElement;

            Action = r.Action;

            base.Reset(parentElement);
        }
        public void Remove(AuthorizationRule rule)
        {
            int index = this.IndexOf(rule);

            if (index >= 0)
            {
                base.BaseRemoveAt(index);
            }
        }
		public void Defaults()
		{
			AuthorizationRule a = new AuthorizationRule(AuthorizationRuleAction.Deny);

			Assert.AreEqual (AuthorizationRuleAction.Deny, a.Action, "A1");
			Assert.IsNotNull (a.Roles, "A2");
			Assert.IsNotNull (a.Users, "A3");
			Assert.IsNotNull (a.Verbs, "A4");
		}
        protected override void Reset(ConfigurationElement parentElement)
        {
            AuthorizationRule parentProviders = parentElement as AuthorizationRule;

            if (parentProviders != null)
            {
                parentProviders.UpdateUsersRolesVerbs();
            }
            base.Reset(parentElement);
            EvaluateData();
        }
 public int IndexOf(AuthorizationRule rule)
 {
     for (int i = 0; i < base.Count; i++)
     {
         if (object.Equals(this.Get(i), rule))
         {
             return(i);
         }
     }
     return(-1);
 }
Beispiel #7
0
        protected override void Reset(ConfigurationElement parentElement)
        {
            AuthorizationRule rule = parentElement as AuthorizationRule;

            if (rule != null)
            {
                rule.UpdateUsersRolesVerbs();
            }
            base.Reset(parentElement);
            this.EvaluateData();
        }
Beispiel #8
0
 public int IndexOf(AuthorizationRule rule)
 {
     for (int x = 0; x < Count; x++)
     {
         if (Object.Equals(Get(x), rule))
         {
             return(x);
         }
     }
     return(-1);
 }
Beispiel #9
0
        public override bool Equals(object obj)
        {
            AuthorizationRule rule = obj as AuthorizationRule;
            bool flag = false;

            if (rule != null)
            {
                this.UpdateUsersRolesVerbs();
                flag = (((rule.Verbs.ToString() == this.Verbs.ToString()) && (rule.Roles.ToString() == this.Roles.ToString())) && (rule.Users.ToString() == this.Users.ToString())) && (rule.Action == this.Action);
            }
            return(flag);
        }
Beispiel #10
0
        protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);
            this.saveMode = saveMode;

            AuthorizationRule source = sourceElement as AuthorizationRule;

            if (source != null)
            {
                this.action = source.Action;
            }
        }
 protected override ConfigurationElement CreateNewElement(string elementName) {
     AuthorizationRule newElement = new AuthorizationRule();
     switch (elementName.ToLower(CultureInfo.InvariantCulture)) {
         case "allow":
             newElement.Action = AuthorizationRuleAction.Allow;
             break;
         case "deny":
             newElement.Action = AuthorizationRuleAction.Deny;
             break;
     }
     return newElement;
 }
		public void AddDuplicate ()
		{
			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();
			AuthorizationRule rule = new AuthorizationRule (AuthorizationRuleAction.Deny);

			rule.Users.Add ("toshok");
			rule.Verbs.Add ("GET");

			col.Add (rule);
			col.Add (rule);

			Assert.AreEqual (2, col.Count, "A1");
			Assert.AreEqual ("toshok", col[0].Users.ToString(), "A2");
		}
Beispiel #13
0
        public override bool Equals(object obj)
        {
            AuthorizationRule auth = obj as AuthorizationRule;

            if (auth == null)
            {
                return(false);
            }

            if (action != auth.Action)
            {
                return(false);
            }

            if (Roles.Count != auth.Roles.Count ||
                Users.Count != auth.Users.Count ||
                Verbs.Count != auth.Verbs.Count)
            {
                return(false);
            }

            int i;

            for (i = 0; i < Roles.Count; i++)
            {
                if (Roles[i] != auth.Roles[i])
                {
                    return(false);
                }
            }

            for (i = 0; i < Users.Count; i++)
            {
                if (Users[i] != auth.Users[i])
                {
                    return(false);
                }
            }

            for (i = 0; i < Verbs.Count; i++)
            {
                if (Verbs[i] != auth.Verbs[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #14
0
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            AuthorizationRule rule  = parentElement as AuthorizationRule;
            AuthorizationRule rule2 = sourceElement as AuthorizationRule;

            if (rule != null)
            {
                rule.UpdateUsersRolesVerbs();
            }
            if (rule2 != null)
            {
                rule2.UpdateUsersRolesVerbs();
            }
            base.Unmerge(sourceElement, parentElement, saveMode);
        }
        public override bool Equals(object obj)
        {
            AuthorizationRule o = obj as AuthorizationRule;
            bool bRet           = false;

            if (o != null)
            {
                UpdateUsersRolesVerbs();

                bRet = (o.Verbs.ToString() == Verbs.ToString() &&
                        o.Roles.ToString() == Roles.ToString() &&
                        o.Users.ToString() == Users.ToString() &&
                        o.Action == Action);
            }
            return(bRet);
        }
Beispiel #16
0
        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            AuthorizationRule newElement = new AuthorizationRule();

            switch (elementName.ToLower(CultureInfo.InvariantCulture))
            {
            case "allow":
                newElement.Action = AuthorizationRuleAction.Allow;
                break;

            case "deny":
                newElement.Action = AuthorizationRuleAction.Deny;
                break;
            }
            return(newElement);
        }
		public void Test_EqualsAndHashCode ()
		{
			AuthorizationRule a = new AuthorizationRule (AuthorizationRuleAction.Deny);
			AuthorizationRule b = new AuthorizationRule (AuthorizationRuleAction.Deny);

			a.Users.Add ("toshok");
			a.Roles.Add ("Admin");
			a.Verbs.Add ("reboot");

			b.Users.Add ("toshok");
			b.Roles.Add ("Admin");
			b.Verbs.Add ("reboot");

			Assert.AreEqual (a, b, "A1");
			Assert.AreEqual (a.GetHashCode (), b.GetHashCode (), "A2");
		}
        protected override void Unmerge(ConfigurationElement sourceElement,
                                        ConfigurationElement parentElement,
                                        ConfigurationSaveMode saveMode)
        {
            AuthorizationRule parentProviders = parentElement as AuthorizationRule;
            AuthorizationRule sourceProviders = sourceElement as AuthorizationRule;

            if (parentProviders != null)
            {
                parentProviders.UpdateUsersRolesVerbs();
            }
            if (sourceProviders != null)
            {
                sourceProviders.UpdateUsersRolesVerbs();
            }
            base.Unmerge(sourceElement, parentElement, saveMode);
        }
 protected override ConfigurationElement CreateNewElement(string elementName)
 {
     AuthorizationRule rule = new AuthorizationRule();
     string str = elementName.ToLower(CultureInfo.InvariantCulture);
     if (str != null)
     {
         if (!(str == "allow"))
         {
             if (str == "deny")
             {
                 rule.Action = AuthorizationRuleAction.Deny;
             }
             return rule;
         }
         rule.Action = AuthorizationRuleAction.Allow;
     }
     return rule;
 }
Beispiel #20
0
 protected void AddRule(AuthorizationRule newRule)
 {
     string virtualFolderPath = FolderTree.SelectedValue;
     Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath);
     SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)config.GetSectionGroup("system.web");
     AuthorizationSection section = (AuthorizationSection)systemWeb.Sections["authorization"];
     section.Rules.Add(newRule);
     try
     {
         config.Save();
         RuleCreationError.Visible = false;
     }
     catch (Exception ex)
     {
         RuleCreationError.Visible = true;
         RuleCreationError.Text = "<div class=\"alert\"><br />An error occurred and the rule was not added. I saw this happen during testing when I attempted to create a rule that the ASP.NET infrastructure realized was redundant. Specifically, I had the rule <i>DENY ALL USERS</i> in one folder, then attempted to add the same rule in a subfolder, which caused ASP.NET to throw an exception.<br /><br />Here's the error message that was thrown just now:<br /><br /><i>" + ex.Message + "</i></div>";
     }
 }
        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            AuthorizationRule rule = new AuthorizationRule();
            string            str  = elementName.ToLower(CultureInfo.InvariantCulture);

            if (str != null)
            {
                if (!(str == "allow"))
                {
                    if (str == "deny")
                    {
                        rule.Action = AuthorizationRuleAction.Deny;
                    }
                    return(rule);
                }
                rule.Action = AuthorizationRuleAction.Allow;
            }
            return(rule);
        }
		public void AddDuplicate2 ()
		{
			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();
			AuthorizationRule rule1 = new AuthorizationRule (AuthorizationRuleAction.Deny);
			AuthorizationRule rule2 = new AuthorizationRule (AuthorizationRuleAction.Allow);

			rule1.Users.Add ("toshok");
			rule1.Verbs.Add ("GET");

			rule2.Users.Add ("toshok");
			rule2.Verbs.Add ("GET");

			col.Add (rule1);
			col.Add (rule2);

			Assert.AreEqual (2, col.Count, "A1");
			Assert.AreEqual ("toshok", col[0].Users.ToString(), "A2");
			Assert.AreEqual (AuthorizationRuleAction.Deny, col[0].Action, "A3");
			Assert.AreEqual (AuthorizationRuleAction.Allow, col[1].Action, "A4");
		}
 public void Add(AuthorizationRule rule)
 {
     BaseAdd(rule, false);
 }
 public void Set(int index, AuthorizationRule rule)
 {
 }
Beispiel #25
0
 protected string GetAction(AuthorizationRule rule)
 {
     return rule.Action.ToString();
 }
		public void Remove (AuthorizationRule rule)
		{
			BaseRemove (rule.Action.ToString());
		}
Beispiel #27
0
 public void Add(AuthorizationRule rule)
 {
 }
 public void Remove(AuthorizationRule rule)
 {
     BaseRemove(rule.Action.ToString());
 }
		public void Add (AuthorizationRule rule)
		{
			BaseAdd (rule, false);
		}
Beispiel #30
0
        protected void CreateRule(object sender, EventArgs e)
        {
            AuthorizationRule newRule;
            if (ActionAllow.Checked) newRule = new AuthorizationRule(AuthorizationRuleAction.Allow);
            else newRule = new AuthorizationRule(AuthorizationRuleAction.Deny);

            if (ApplyRole.Checked && UserRoles.SelectedIndex > 0)
            {
                newRule.Roles.Add(UserRoles.Text);
                AddRule(newRule);
            }
            else if (ApplyUser.Checked && UserList.SelectedIndex > 0)
            {
                newRule.Users.Add(UserList.Text);
                AddRule(newRule);
            }
            else if (ApplyAllUsers.Checked)
            {
                newRule.Users.Add("*");
                AddRule(newRule);
            }
            else if (ApplyAnonUser.Checked)
            {
                newRule.Users.Add("?");
                AddRule(newRule);
            }
        }
Beispiel #31
0
 public void Remove(AuthorizationRule rule)
 {
 }
 public void Remove(AuthorizationRule rule) {
     int index = IndexOf(rule);
     if (index >= 0) {
         BaseRemoveAt(index);
     }
 }
 public void Add(AuthorizationRule rule)
 {
     this.BaseAdd(-1, rule);
 }
 public int IndexOf(AuthorizationRule rule) {
     for (int x = 0; x < Count; x++) {
         if (Object.Equals(Get(x), rule)) {
             return x;
         }
     }
     return -1;
 }
 public void Set(int index, AuthorizationRule rule) {
     BaseAdd(index, rule);
 }
 // public methods
 public void Add(AuthorizationRule rule) {
     BaseAdd(-1, rule); // add to the end of the list and dont overwrite dups!
 }
        protected override object GetElementKey(ConfigurationElement element)
        {
            AuthorizationRule rule = (AuthorizationRule)element;

            return(rule.Action.ToString());
        }
		public void PostDeserialize ()
		{
			AuthorizationRule rule;
			MethodInfo mi = typeof (AuthorizationRule).GetMethod ("PostDeserialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object[] parms = new object[0];
			bool failed;

			/* 1 */
			failed = true;
			try {
				rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
				mi.Invoke (rule, parms);
			}
			catch (TargetInvocationException e) {
				Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A1");
				failed = false;
			}
			Assert.IsFalse (failed, "A1");

			/* 2 */
			rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
			rule.Users.Add ("toshok");
			mi.Invoke (rule, parms);

			/* 2 */
			rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
			rule.Users.Add ("toshok");
			mi.Invoke (rule, parms);

			/* 3-4 */
			rule = new AuthorizationRule (AuthorizationRuleAction.Deny);
			rule.Users.Add ("toshok");
			rule.Users.Add ("chris");
			rule.Roles.Add ("admin");
			rule.Roles.Add ("wheel");
			rule.Verbs.Add ("GET");
			rule.Verbs.Add ("PUT");

			mi.Invoke (rule, parms);
		}
 public int IndexOf(AuthorizationRule rule)
 {
     return(BaseIndexOf(rule));
 }
 public int IndexOf(AuthorizationRule rule)
 {
   return default(int);
 }
Beispiel #41
0
 protected string GetRole(AuthorizationRule rule)
 {
     return rule.Roles.ToString();
 }
 public void Add(AuthorizationRule rule)
 {
 }
		public int IndexOf (AuthorizationRule rule)
		{
			return BaseIndexOf (rule);
		}
Beispiel #44
0
        public static void Main()
        {
            // <Snippet1>
            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");
            // </Snippet1>

            // <Snippet2>
            // Get the section.
            AuthorizationSection authorizationSection =
                (AuthorizationSection)configuration.GetSection(
                    "system.web/authorization");
            // </Snippet2>

            // <Snippet3>
            // Get the authorization rule collection.
            AuthorizationRuleCollection authorizationRuleCollection =
                authorizationSection.Rules;
            // </Snippet3>

            // <Snippet4>
            // Create an authorization rule object.
            AuthorizationRuleAction action =
                AuthorizationRuleAction.Deny;
            AuthorizationRule authorizationRule =
                new System.Web.Configuration.AuthorizationRule(action);
            // </Snippet4>


            // <Snippet5>
            // Create a new 'AuthorizationSection' object.
            AuthorizationSection newauthorizationSection =
                new System.Web.Configuration.AuthorizationSection();

            // </Snippet5>


            // <Snippet6>
            // Using the AuthorizationRuleCollection Add method.

            // Set the action property.
            authorizationRule.Action =
                AuthorizationRuleAction.Allow;
            // Define the new rule to add to the collection.
            authorizationRule.Users.Add("userName");
            authorizationRule.Roles.Add("admin");
            authorizationRule.Verbs.Add("POST");

            // Add the new rule to the collection.
            authorizationSection.Rules.Add(authorizationRule);
            // </Snippet6>

            // <Snippet7>
            // Using the AuthorizationRuleCollection Clear method.
            authorizationSection.Rules.Clear();
            // </Snippet7>

            // <Snippet8>
            // Using the AuthorizationRuleCollection RemoveAt method.
            authorizationRuleCollection.RemoveAt(0);
            // </Snippet8>

            // <Snippet9>
            // Get the rule collection index.
            System.Int32 ruleIndex =
                authorizationSection.Rules.IndexOf(authorizationRule);
            // </Snippet9>

            // <Snippet10>
            // Remove the rule from the collection.
            authorizationSection.Rules.Remove(authorizationRule);

            // </Snippet10>

            // <Snippet11>
            // Using the AuthorizationRuleCollection Set method.

            // Define the rule to add to the collection.

            // Define the collection index.
            System.Int32 rIndex = 0;

            // Set the rule in the collection.
            authorizationRuleCollection.Set(rIndex,
                                            authorizationRule);
            // </Snippet11>


            // <Snippet12>
            // Show how to access the Rules elements.
            StringBuilder rules = new StringBuilder();

            for (System.Int32 i = 0;
                 i < authorizationSection.Rules.Count - 1; i++)
            {
                rules.Append("Action: " +
                             authorizationSection.Rules[i].Action.ToString());

                // Get the Verbs.
                System.Int32 verbsCount =
                    authorizationSection.Rules[i].Verbs.Count;
                for (System.Int32 v = 0; v < verbsCount; v++)
                {
                    rules.AppendLine(
                        authorizationSection.Rules[i].Verbs[v]);
                }

                // Get the Roles.
                System.Int32 rolesCount =
                    authorizationSection.Rules[i].Roles.Count;
                for (System.Int32 r = 0; r < rolesCount; r++)
                {
                    rules.AppendLine(authorizationSection.Rules[i].Roles[r]);
                }

                // Get the Users.
                System.Int32 usersCount =
                    authorizationSection.Rules[i].Users.Count;
                for (System.Int32 u = 0; u < usersCount; u++)
                {
                    rules.AppendLine(authorizationSection.Rules[i].Users[u]);
                }
            }

            // </Snippet12>

            // <Snippet13>
            // Using the AuthorizationRuleCollection Get method.
            AuthorizationRule authRule =
                authorizationRuleCollection.Get(0);
            // </Snippet13>
        }
		public void Set (int index, AuthorizationRule rule)
		{
			if (BaseGet(index) != null)
				BaseRemoveAt(index);
			BaseAdd(index, rule);
		}
 public void Set(int index, AuthorizationRule rule)
 {
     this.BaseAdd(index, rule);
 }
Beispiel #47
0
 public int IndexOf(AuthorizationRule rule)
 {
     return(default(int));
 }
 public void Remove(AuthorizationRule rule)
 {
 }
Beispiel #49
0
 public void Set(int index, AuthorizationRule rule)
 {
 }
		public void GetElementKey ()
		{
			MethodInfo minfo = typeof (AuthorizationRuleCollection).GetMethod ("GetElementKey", BindingFlags.Instance | BindingFlags.NonPublic);
			AuthorizationRuleCollection col = new AuthorizationRuleCollection ();

			AuthorizationRule rule = new AuthorizationRule (AuthorizationRuleAction.Deny);

			rule.Users.Add ("toshok");
			rule.Verbs.Add ("GET");

			col.Add (rule);

			object[] args = new object[1];
			args[0] = rule;
			string key = (string)minfo.Invoke (col, args);

			Assert.AreEqual ("Deny", key, "A1");
		}
Beispiel #51
0
 // public methods
 public void Add(AuthorizationRule rule)
 {
     BaseAdd(-1, rule); // add to the end of the list and dont overwrite dups!
 }
 public void Add(AuthorizationRule rule)
 {
     this.BaseAdd(-1, rule);
 }
		public void SerializeElement ()
		{
			StringWriter sw;
			XmlWriter writer;
			AuthorizationRule rule;
			MethodInfo mi = typeof (AuthorizationRule).GetMethod ("SerializeElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object[] parms = new object[2];
			bool failed;

			/* 1 */
			failed = true;
			try {
				sw = new StringWriter ();
				writer = new XmlTextWriter (sw);

				rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
				parms[0] = writer;
				parms[1] = false;
				mi.Invoke (rule, parms);
			}
			catch (TargetInvocationException e) {
				Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A1");
				failed = false;
			}
			Assert.IsFalse (failed, "A1");

			/* 2 */
			sw = new StringWriter ();
			writer = new XmlTextWriter (sw);
			rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
			rule.Users.Add ("toshok");
			parms[0] = writer;
			parms[1] = false;
			mi.Invoke (rule, parms);

			Assert.AreEqual ("<allow users=\"toshok\" />", sw.ToString(), "A2");

			/* 2 */
			sw = new StringWriter ();
			writer = new XmlTextWriter (sw);
			rule = new AuthorizationRule (AuthorizationRuleAction.Allow);
			rule.Users.Add ("toshok");
			parms[0] = writer;
			parms[1] = true;
			mi.Invoke (rule, parms);

			Assert.AreEqual ("<allow users=\"toshok\" />", sw.ToString(), "A2");

			/* 3-4 */
			sw = new StringWriter ();
			writer = new XmlTextWriter (sw);
			rule = new AuthorizationRule (AuthorizationRuleAction.Deny);
			rule.Users.Add ("toshok");
			rule.Users.Add ("chris");
			rule.Roles.Add ("admin");
			rule.Roles.Add ("wheel");
			rule.Verbs.Add ("GET");
			rule.Verbs.Add ("PUT");
			parms[0] = writer;
			parms[1] = true;
			bool b = (bool)mi.Invoke (rule, parms);

			Assert.AreEqual ("<deny roles=\"admin,wheel\" users=\"toshok,chris\" verbs=\"GET,PUT\" />", sw.ToString(), "A3");
			Assert.IsTrue (b, "A4");
		}
Beispiel #54
0
        protected override Object GetElementKey(ConfigurationElement element)
        {
            AuthorizationRule rule = (AuthorizationRule)element;

            return(rule._ActionString);
        }
 public int IndexOf(AuthorizationRule rule)
 {
     for (int i = 0; i < base.Count; i++)
     {
         if (object.Equals(this.Get(i), rule))
         {
             return i;
         }
     }
     return -1;
 }
Beispiel #56
0
 protected string GetUser(AuthorizationRule rule)
 {
     return rule.Users.ToString();
 }