Skip to content

Commit

Permalink
Lifted restriction on setting SecurityTrimmingEnabled from true to fa…
Browse files Browse the repository at this point in the history
…lse because the IsReadOnly functionality blocks this anyway. Changed IsAccessibleToUser to always return true while the site map is being built. Fixes #102.
  • Loading branch information
NightOwl888 committed Jun 25, 2013
1 parent a14d611 commit ca71118
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/LockableSiteMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public override string ResourceKey
}
}

public sealed override bool SecurityTrimmingEnabled
{
get { return base.SecurityTrimmingEnabled; }
set
{
this.ThrowIfReadOnly();
base.SecurityTrimmingEnabled = value;
}
}

protected virtual void ThrowIfReadOnly()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@
<data name="ResourceNotFoundWithClassAndKey" xml:space="preserve">
<value>The resource object with classname '{0}' and key '{1}' was not found.</value>
</data>
<data name="SecurityTrimmingCannotBeDisabled" xml:space="preserve">
<value>Security trimming cannot be disabled again after it is enabled.</value>
</data>
<data name="SiteMapNodeReadOnly" xml:space="preserve">
<value>SiteMapNode is readonly, property '{0}' cannot be modified.</value>
</data>
Expand Down
16 changes: 8 additions & 8 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ public virtual void HintNeighborhoodNodes(ISiteMapNode node, int upLevel, int do
/// </exception>
public virtual bool IsAccessibleToUser(ISiteMapNode node)
{
// If the sitemap is still being constructed, always
// make all nodes accessible regardless of security trimming.
if (!IsReadOnly)
{
return true;
}
if (!SecurityTrimmingEnabled)
{
return true;
Expand All @@ -526,16 +532,10 @@ public virtual bool IsAccessibleToUser(ISiteMapNode node)
/// <summary>
/// Gets a Boolean value indicating whether a site map provider filters site map nodes based on a user's role.
/// </summary>
/// <remarks>Once security trimming is enabled, it cannot be disabled again.</remarks>
public bool SecurityTrimmingEnabled
public virtual bool SecurityTrimmingEnabled
{
get { return this.securityTrimmingEnabled; }
set
{
if (value == false && this.securityTrimmingEnabled == true)
throw new System.Security.SecurityException(Resources.Messages.SecurityTrimmingCannotBeDisabled);
this.securityTrimmingEnabled = value;
}
set { this.securityTrimmingEnabled = value; }
}

/// <summary>
Expand Down

0 comments on commit ca71118

Please sign in to comment.