Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

PortalSiteMapProvider and security trimming

  Asked By: Krista    Date: Jun 16    Category: Sharepoint    Views: 2945

I'm trying to use PortalSiteMapProvider to populate a TreeView on a custom control. Everything works fine but I have one problem that I can't find a solution yet. The way our sites are set up a user can have access to a node on a level 1 node, has no access to any of the direct children of level1 but has access to one of the grandchildren of level1 node:
site1
Site1.1 (user has access)
Site1.1.1 (NO Access)
Site1.1.2 (NO Access)
Site1.1.2.1 (has access)
Site1.1.2 (NO Access)
As you can see the hierarchy of access breaks on 1.1.2 level. When I'm retrieving the SiteMapNodes I can't get Site1.1.2.1.
Is there a way to get to that node with security trimming enabled? Any help is greatly appreciated. I'll paste example code too.


Public Class NavigationTest
Inherits SPControl
Implements INamingContainer
#Region "Private Fields"""
Private _tree As TreeView

Private _provider As PortalSiteMapProvider
Private _siteMapProvider As String = "CurrentNavSiteMapProvider"
Private _startNodeKey As String
#End Region
#Region "Public Properties"
Public Property SiteMapProvider() As String
Get
Return _siteMapProvider
End Get
Set(ByVal value As String)
_siteMapProvider = value
End Set
End Property

Public Property StartNodeKey() As String
Get
Return _startNodeKey
End Get
Set(ByVal value As String)
_startNodeKey = value
End Set
End Property

#End Region

Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)

Dim siteMapProvider As SiteMapProvider = SiteMap.Providers(_siteMapProvider)
If siteMapProvider Is Nothing Then
Exit Sub
End If

InitPortalSiteMapProvider(siteMapProvider)
End Sub
#Region "New Code"

Private Function AddNode(ByVal parent As TreeNode, ByVal label As String, ByVal url As String, ByVal imgUrl As String) As TreeNode
Dim n As New TreeNode()
If Not String.IsNullOrEmpty(imgUrl) Then
n.ImageUrl = imgUrl
End If
n.Text = label
If Not String.IsNullOrEmpty(url) Then
n.NavigateUrl = url
End If
If parent Is Nothing Then
_tree.Nodes.Add(n)
Else
parent.ChildNodes.Add(n)
End If
Return n
End Function
Private Function AddPageNode(ByVal parent As TreeNode, ByVal label As String, ByVal url As String, Optional ByVal imgUrl As String = "") As TreeNode
Return AddNode(parent, label, url, "/_layouts/images/Page.GIF")
End Function
Private Function AddSiteNode(ByVal parent As TreeNode, ByVal label As String, ByVal url As String, Optional ByVal imgUrl As String = "") As TreeNode
Return AddNode(parent, label, url, "/_layouts/images/Globe.GIF")
End Function
Private Sub AddPageNodes(ByVal portalNode As PortalSiteMapNode, ByRef currentTreeNode As TreeNode)
Dim query As SPQuery = New SPQuery()
query.Query = "<Neq><FieldRef Name=""FSObjType\""></FieldRef><Value Type=""Integer"">1</Value></Neq>"
Dim pageNodes As SiteMapNodeCollection = _provider.GetCachedListItemsByQuery(portalNode.WebNode, NRC.ClientPlatform.NRCCP.SitePagesListInstanceName, query, SPContext.Current.Web)
For Each pageNode As SiteMapNode In pageNodes
AddPageNode(currentTreeNode, pageNode.Title, pageNode.Url)
Next
End Sub
Private Sub PopulateChildNodes(ByVal parent As TreeNode, ByVal nodes As SiteMapNodeCollection)
Try
For i As Integer = 0 To nodes.Count - 1 Step 1
Dim childWeb As PortalSiteMapNode = CType(nodes(i), PortalSiteMapNode)
Dim currentNode As TreeNode = parent
currentNode = AddSiteNode(parent, childWeb.Title, String.Format("{0}/default.aspx", childWeb.Url))
AddPageNodes(childWeb, currentNode)
PopulateChildNodes(currentNode, childWeb.ChildNodes)
Next
Catch ex As Exception
NRC.AuditLog.Log("Navigation.PopulateChildNodes", ex)
Throw (ex)
End Try
End Sub
#End Region

Private Sub PopulateTree()
Dim startingNode As PortalSiteMapNode = CType(GetStartingNode(), PortalSiteMapNode)
Dim nodes As SiteMapNodeCollection = _provider.GetChildNodes(startingNode, NodeTypes.Area Or NodeTypes.Page, NodeTypes.Area Or NodeTypes.Page)
Dim rootNode As TreeNode = AddSiteNode(Nothing, startingNode.Title, startingNode.Url)
PopulateChildNodes(rootNode, nodes)
End Sub
Private Sub AddTree()
_tree = New TreeView
PopulateTree()
Me.Controls.Add(_tree)
End Sub
Protected Overloads Overrides Sub CreateChildControls()
MyBase.CreateChildControls()

Try
If _provider Is Nothing Then
Throw New HttpException([String].Format("Invalid SiteMapProvider: {0}", _siteMapProvider))
End If

AddTree()

Catch ex As Exception
Controls.Add(New LiteralControl(ex.Message))
End Try
End Sub

Private Sub InitPortalSiteMapProvider(ByVal siteMapProvider As SiteMapProvider)
If TypeOf siteMapProvider Is PortalSiteMapProvider Then
_provider = TryCast(siteMapProvider, PortalSiteMapProvider)
_provider.DynamicChildLimit = 0
_provider.EncodeOutput = True
_provider.IncludeAuthoredLinks = False
_provider.IncludeHeadings = False
_provider.IncludePages = PortalSiteMapProvider.IncludeOption.Never
_provider.IncludeSubSites = PortalSiteMapProvider.IncludeOption.Always
_provider.RequireUniqueKeysForNodes = True
End If
End Sub

Private Function GetStartingNode() As SiteMapNode
Dim startingNode As SiteMapNode = Nothing

If Not [String].IsNullOrEmpty(_startNodeKey) Then
startingNode = _provider.FindSiteMapNodeFromKey(_startNodeKey)
End If

If startingNode Is Nothing Then
startingNode = _provider.RootNode
'startingNode = _provider.TryGetRootNode
End If

Return startingNode
End Function

Public Sub New()

End Sub
End Class

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Elisa Santos     Answered On: Jun 16

well, you said you are looping through the nodes  with elevated privilegies? I can't see it on your listing (but I'm not so good in VB.NET, I always prefer C# :) ). try updating your PopulateChildNodes function  to iterate with iterated privilegies, but add the node only if current user  has corresponded rights.

 
Didn't find what you were looking for? Find more on PortalSiteMapProvider and security trimming Or get search suggestion and latest updates.