* ToolTask.cs (ProcessOuputTool): Move logging of tool
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / AuthorizationSection.cs
index a15acb81afae2587963b1c419efdfae8e41f78c6..521620a3994def766f087a08d1f9fe19e0e3d073 100644 (file)
@@ -30,6 +30,7 @@
 
 using System;
 using System.Configuration;
+using System.Security.Principal;
 
 #if NET_2_0
 
@@ -42,7 +43,7 @@ namespace System.Web.Configuration {
 
                static AuthorizationSection ()
                {
-                       rulesProp = new ConfigurationProperty ("", typeof (AuthorizationRuleCollection), null,
+                       rulesProp = new ConfigurationProperty (String.Empty, typeof (AuthorizationRuleCollection), null,
                                                               null, PropertyHelper.DefaultValidator,
                                                               ConfigurationPropertyOptions.IsDefaultCollection);
                        properties = new ConfigurationPropertyCollection ();
@@ -50,7 +51,6 @@ namespace System.Web.Configuration {
                        properties.Add (rulesProp);
                }
 
-               [MonoTODO]
                protected override void PostDeserialize()
                {
                        base.PostDeserialize ();
@@ -65,6 +65,21 @@ namespace System.Web.Configuration {
                        get { return properties; }
                }
 
+
+               internal bool IsValidUser (IPrincipal user, string verb)
+               {
+                       string username = (user == null) ? String.Empty : user.Identity.Name;
+                       foreach (AuthorizationRule rule in Rules) {
+                               if (rule.Verbs.Count != 0 && !rule.CheckVerb (verb))
+                                       continue;
+
+                               if (rule.CheckUser (username) || (user != null && rule.CheckRole(user)))
+                                       return (rule.Action == AuthorizationRuleAction.Allow);
+                       }
+
+                       return true;
+               }
+
        }
 
 }