Merge pull request #2916 from ludovic-henry/fix-40306
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / AuthorizationRule.cs
index f09068863cc2b182315b85aad235af15f5766e00..f5ebd6cd2ea6e0b6f3d6f0e03297d7552a59b8ee 100644 (file)
@@ -34,8 +34,9 @@ using System.Security.Principal;
 using System.Configuration;
 using System.ComponentModel;
 using System.Xml;
+using System.Globalization;
+using System.Web.Util;
 
-#if NET_2_0
 
 namespace System.Web.Configuration {
 
@@ -47,7 +48,8 @@ namespace System.Web.Configuration {
                static ConfigurationPropertyCollection properties;
 
                AuthorizationRuleAction action;
-
+               ConfigurationSaveMode saveMode = ConfigurationSaveMode.Full;
+                       
                static AuthorizationRule ()
                {
                        rolesProp = new ConfigurationProperty ("roles", typeof (StringCollection), null,
@@ -125,10 +127,13 @@ namespace System.Web.Configuration {
                        return hashCode;
                }
 
-               [MonoTODO]
-               protected override bool IsModified ()
+               [MonoTODO ("Not implemented")]
+               protected internal override bool IsModified ()
                {
-                       throw new NotImplementedException ();
+                       if (((CommaDelimitedStringCollection)Roles).IsModified || ((CommaDelimitedStringCollection)Users).IsModified || ((CommaDelimitedStringCollection)Verbs).IsModified)
+                               return true;
+
+                       return false;
                }
 
                void VerifyData ()
@@ -151,7 +156,7 @@ namespace System.Web.Configuration {
                        VerifyData ();
                }
 
-               protected override void Reset (ConfigurationElement parentElement)
+               protected internal override void Reset (ConfigurationElement parentElement)
                {
                        AuthorizationRule r = (AuthorizationRule)parentElement;
                        Action = r.Action;
@@ -159,14 +164,16 @@ namespace System.Web.Configuration {
                        base.Reset (parentElement);
                }
 
-               [MonoTODO]
-               protected override void ResetModified ()
+               protected internal override void ResetModified ()
                {
                        base.ResetModified ();
                }
 
-               protected override bool SerializeElement (XmlWriter writer, bool serializeCollectionKey)
+               protected internal override bool SerializeElement (XmlWriter writer, bool serializeCollectionKey)
                {
+                       if (saveMode != ConfigurationSaveMode.Full && !IsModified ())
+                               return true;
+                       
                        PreSerialize (writer);
 
                        writer.WriteStartElement (action == AuthorizationRuleAction.Allow ? "allow" : "deny");
@@ -182,16 +189,19 @@ namespace System.Web.Configuration {
                        return true;
                }
 
-               [MonoTODO]
-               protected override void SetReadOnly ()
+               protected internal override void SetReadOnly ()
                {
                        base.SetReadOnly();
                }
 
-               [MonoTODO]
-               protected override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
+               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;
                }
 
                public AuthorizationRuleAction Action {
@@ -217,7 +227,7 @@ namespace System.Web.Configuration {
                        get { return (StringCollection) base [verbsProp];}
                }
 
-               protected override ConfigurationPropertyCollection Properties {
+               protected internal override ConfigurationPropertyCollection Properties {
                        get { return properties; }
                }
 
@@ -225,7 +235,7 @@ namespace System.Web.Configuration {
                internal bool CheckVerb (string verb)
                {
                        foreach (string v in Verbs) {
-                               if (String.Compare (v, verb, true) == 0)
+                               if (String.Compare (v, verb, true, Helpers.InvariantCulture) == 0)
                                        return true;
                        }
                        return false;
@@ -234,7 +244,7 @@ namespace System.Web.Configuration {
                internal bool CheckUser (string user)
                {
                        foreach (string u in Users) {
-                               if (String.Compare (u, user, true) == 0 ||
+                               if (String.Compare (u, user, true, Helpers.InvariantCulture) == 0 ||
                                    u == "*" ||
                                    (u == "?" && user == ""))
                                        return true;
@@ -255,5 +265,4 @@ namespace System.Web.Configuration {
 
 }
 
-#endif