Don't cache child nodes when security trimming is enabled.
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 12 Nov 2010 02:16:17 +0000 (21:16 -0500)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 12 Nov 2010 02:19:12 +0000 (21:19 -0500)
When SecurityTrimmingEnabled is set to true for the node, the cached children
collection also depends on the IPrincipal set for the current context.

Fixes bug #641449.

mcs/class/System.Web/System.Web/SiteMapNode.cs

index e1fb52011f9f6017f96a3eb4f6ee86fbda1e9d2f..b1660b8752c2365c8ff4981c3682921cafbd764c 100644 (file)
@@ -35,6 +35,7 @@ using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.ComponentModel;
 using System.Resources;
+using System.Security.Principal;
 
 namespace System.Web {
        public class SiteMapNode : IHierarchyData, INavigateUIData, ICloneable {
@@ -177,12 +178,20 @@ namespace System.Web {
 
                public virtual SiteMapNodeCollection ChildNodes {
                        get {
-                               if (childNodes == null)
+                               if (provider.SecurityTrimmingEnabled) {
+                                       IPrincipal p = HttpContext.Current.User;
+                                       if ((user == null && user != p) || user != null && user != p) {
+                                               user = p;
+                                               childNodes = provider.GetChildNodes (this);
+                                       }
+                               } else if (childNodes == null) {
                                        childNodes = provider.GetChildNodes (this);
+                               }
                                return childNodes;
                        } 
                        set {
                                CheckWritable ();
+                               user = null;
                                childNodes = value;
                        }
                }
@@ -439,6 +448,7 @@ namespace System.Web {
                string resourceKey;
                SiteMapNode parent;
                SiteMapNodeCollection childNodes;
+               IPrincipal user;
                #endregion
                
        }