• MOSS提升权限,模拟


    在MOSS代码中用来提升权限,模拟成站点管理员的权限,在这过程需要用户MOSS里的对象模型里的

    SPSecurity.RunWithElevatedPrivileges

    来进行。

    SPSecurity.RunWithElevatedPrivileges对象是可以将当前用户在代码里的安全上下文凭据提升模拟成当前站点的管理员的权限运行此代码。 如第一种情况: //模拟提升权限

    SPSecurity.RunWithElevatedPrivileges(delegate

     {

    //创建指定站点集

    using (SPSite site = new SPSite(http://crmg-ea/mdms))

    { //打开网站

    using (SPWeb web = site.OpenWeb())

    { //允许更新网站

    web.AllowUnsafeUpdates = true;

    //打开所属的文档库

    SPList list = web.Lists[ListName];

    ………….

    web.AllowUnsafeUpdates = false;

    }

    }

    });

     这种情况下创建的SPSite对象会以全新的身份就是以站点管理员(SPSAdmin)的身份来运行下面的方法体的而不是当前登录用户真正在此网站里的权限。

    如第二种情况:

    //创建指定站点集

    using (SPSite site = new SPSite(http://crmg-ea/mdms))

    { //模拟提升权限

    SPSecurity.RunWithElevatedPrivileges(delegate

    { //打开网站

    using (SPWeb web = site.OpenWeb())

     { //允许更新网站

    web.AllowUnsafeUpdates = true;

    //打开所属的文档库

    SPList list = web.Lists[ListName];

     ………….

    web.AllowUnsafeUpdates = false;

    }

    });

    } 这种情况那么所创建的用户安全上下文的权限就是以当前登录用户在此网站中真正实际权限来运行接下来的代码方法体,虽然代码中创建的SPWeb对象打开网站是在SPSecurity.RunWithElevatedPrivileges模拟权限的方法块中运行,但根据代码的运行结果可以看出SPSecurity.RunWithElevatedPrivileges对象并没有起到提升权限的效果。 这两种说明了在SPSecurity.RunWithElevatedPrivileges对象方法块中创建站点SPSite对象所产生的运行效果是完全不同的

  • 相关阅读:
    springboot笔记(五章)整合持久层技术
    Java基础复习(一)
    springboot复习
    JUC(2)
    JUC(1)
    springboot笔记(一~四章)入门、基础配置、整合视图技术、整合Web开发
    JVM复习
    NIO(New IO)
    hive 函数
    hive基础知识
  • 原文地址:https://www.cnblogs.com/IsNull/p/1812393.html
Copyright © 2020-2023  润新知