1
目前我想安全修剪全球导航,使用xmlsitemapprovider跨越所有网站集的自定义全局导航。一切工作正常,但是因为我使用web.allusers它不显示节点,除非明确授予用户访问权限。由于我的大部分权限都基于Active Directory组,因此用户在访问该站点之后才能看到这些节点。如何让这些用户无需首先访问该网站即可显示这些节点?SharePoint 2010中的安全调整与web.allusers
public class CustomNavSecurityTrim : XmlSiteMapProvider
{
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
try
{
if (node == null)
{
throw new ArgumentNullException("node");
}
if (context == null)
{
throw new ArgumentNullException("context");
}
if (!base.SecurityTrimmingEnabled)
{
return true;
}
if (string.IsNullOrEmpty(node.Url))
{
return this.IsGranted(context, node.ChildNodes);
}
return this.IsGranted(context, node);
}
catch
{
return false;
}
}
private bool IsGranted(HttpContext context, SiteMapNode node)
{
bool isGranted = false;
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPWeb web = new SPSite(SPContext.Current.Site.MakeFullUrl(node.Url)).OpenWeb())
{
SPUser user = web.AllUsers[context.User.Identity.Name];
if (user != null)
{
try
{
if ((node.Roles != null) && (node.Roles.Count > 0))
{
foreach (string str in node.Roles)
{
isGranted = (str == "*") || (user.Groups[str] != null);
if (isGranted)
{
break;
}
}
}
isGranted = web.DoesUserHavePermissions(user.LoginName, SPBasePermissions.EmptyMask | SPBasePermissions.ViewPages);
}
catch
{
}
}
}
});
return isGranted;
}
private bool IsGranted(HttpContext context, SiteMapNodeCollection childNodes)
{
bool flag = false;
foreach (SiteMapNode node in childNodes)
{
flag = this.IsGranted(context, node);
if (flag)
{
return flag;
}
this.IsGranted(context, node.ChildNodes);
}
return false;
}
}
}
我有超过45网站集,我试图实现全球导航利用xmlsitemapprovider,我需要是安全通过SharePoint权限修剪。你能提供一个如何在这个解决方案中使用'EnsureUser'的例子吗? – tunacode
的Ondrej讨论和关注的问题是,如果你实现你的导航像这样和命令执行**为每个用户** **每次**,你将有性能瓶颈。您需要实施某种缓存,因此访问权并不总是被重新计算。 –
有没有一种方法可以在使用PowerShell时创建用户'EnsureUser'?我将如何缓存用户的访问权限?我并不是要求你写代码,但如果你能提供一个例子或可能的解决方案,我会非常感激。谢谢! – tunacode