Explorar el Código

2006-01-03 Chris Toshok <[email protected]>

	* AuthorizationSection.cs (IsValidUser): add analogous method from
	AuthorizationConfig.cs.

	* AuthorizationRule.cs: add predicates for Verb, User, and Role
	analogous to what existed in AuthorizationConfig.cs.


svn path=/trunk/mcs/; revision=55037
Chris Toshok hace 20 años
padre
commit
be1269d728

+ 29 - 0
mcs/class/System.Web/System.Web.Configuration_2.0/AuthorizationRule.cs

@@ -30,6 +30,7 @@
 
 using System;
 using System.Collections.Specialized;
+using System.Security.Principal;
 using System.Configuration;
 using System.ComponentModel;
 using System.Xml;
@@ -218,6 +219,34 @@ namespace System.Web.Configuration {
 			get { return properties; }
 		}
 
+
+		internal bool CheckVerb (string verb)
+		{
+			foreach (string v in Verbs) {
+				if (verb == v)
+					return true;
+			}
+			return false;
+		}
+
+		internal bool CheckUser (string user)
+		{
+			foreach (string u in Users) {
+				if (u == user)
+					return true;
+			}
+			return false;
+		}
+
+		internal bool CheckRole (IPrincipal user)
+		{
+			foreach (string r in Roles) {
+				if (user.IsInRole (r))
+					return true;
+			}
+			return false;
+		}
+
 	}
 
 }

+ 15 - 0
mcs/class/System.Web/System.Web.Configuration_2.0/AuthorizationSection.cs

@@ -30,6 +30,7 @@
 
 using System;
 using System.Configuration;
+using System.Security.Principal;
 
 #if NET_2_0
 
@@ -65,6 +66,20 @@ namespace System.Web.Configuration {
 			get { return properties; }
 		}
 
+
+		internal bool IsValidUser (IPrincipal user, string verb)
+		{
+			foreach (AuthorizationRule rule in Rules) {
+				if (!rule.CheckVerb (verb))
+					continue;
+
+				if (rule.CheckUser (user.Identity.Name) || rule.CheckRole(user))
+					return (rule.Action == AuthorizationRuleAction.Allow);
+			}
+
+			return true;
+		}
+
 	}
 
 }

+ 8 - 0
mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog

@@ -1,3 +1,11 @@
+2006-01-03  Chris Toshok  <[email protected]>
+
+	* AuthorizationSection.cs (IsValidUser): add analogous method from
+	AuthorizationConfig.cs.
+
+	* AuthorizationRule.cs: add predicates for Verb, User, and Role
+	analogous to what existed in AuthorizationConfig.cs.
+
 2005-12-11  Chris Toshok  <[email protected]>
 
 	* WebConfigurationManager.cs (OpenMachineConfiguration): just call