【问题标题】:Methods of running with Elevated Privileges in a MOSS Publishing Site在 MOSS 发布站点中以高权限运行的方法
【发布时间】:2017-08-11 19:51:02
【问题描述】:

我想知道为什么下面列出的两种方法不能提供相同的安全调整。

预期结果:这两种方法都可以完全访问当前网站集中的所有内容

实际结果:使用方法#1时发生安全修整

  • 方法 #2 可正常用于从其他网站检索内容,但方法 #1 不能。

  • 这两种方法都以匿名模式提供跨网络访问,并且都适用于站点管理员帐户。

  • 层级管理者审批者编辑者的区别在于。方法 #1 不提供跨网络的管理员访问权限。

方法#1

using (SystemOperation op = new SystemOperation())
{ 
    //Do an operation that requires retrieving across webs
}

public class SystemOperation : IDisposable
{
    private WindowsImpersonationContext ctx;

    public SystemOperation()
    {
        if (!WindowsIdentity.GetCurrent().IsSystem)
        {
            ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
        }
    }

    public void Dispose()
    {
        this.Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool all)
    {
        if (ctx != null)
        {
            ctx.Undo();
        }
    }
}

方法#2:

   Microsoft.Sharepoint.SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        //Do an operation that requires retrieving across webs
    });

【问题讨论】:

  • 对不起,我没有回答您的问题,但我很好奇您为什么要使用方法 1?此外,代码格式似乎在您的问题中搞砸了。
  • 您需要 #1 的原因是因为 RunWithElevatedPrivileges 并非在所有情况下都有效,例如访问配置文件管理器。
  • SPSite.SystemAccount.UserToken(以及使用此令牌的新 SPSite())方法怎么样?这如何适应?
  • bzlm - 一个对比 RWEP 和 SPUserToken 的例子。 tinyurl.com/cdmvxe,这篇文章非常悲观,因为根据 MS RWEP “应该谨慎使用。你不应该为低权限的人暴露直接的、不受控制的机制来规避授予他们的权限”。

标签: sharepoint sharepoint-2007 moss


【解决方案1】:

RunWithElevatedPrivileges 提供两个独立的权限。首先是将用户的 Windows 身份提升为 AppPool 帐户,其次是将身份提升为 SharePoint\System 帐户,这是一个提供完全控制(在 SharePoint 意义上)的内置安全帐户。构建 SP 对象(如 SPSite)时使用内部 SharePoint 帐户。

所以基本上这将取决于您如何构建代码以及何时实例化影响权限如何发挥作用的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-10
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    相关资源
    最近更新 更多