zoukankan      html  css  js  c++  java
  • SharePoint2010l自定义工作流条件时提权需要注意的地方

    摘要

    开发SharePoint自定义工作流的时候为了获取当前的站点对象,如果利用输入参数的WorkflowContext对象来获取SPWeb对象将会导致提权不成功。

    环境是非AD单服务器场景,默认用户是系统的管理员,在开发一个自定义工作流条件的时候遇到了账号在管理员账号测试下的时候都能够通过,尽管代码做了提权处理但是在具有Contributor权限的测试账号运行时一直失败,没有提权的时候会遇到Access Denied,提权后遇到工作流启动被Cancell,借这个机会Figure Out了几个事情:

    1. 众所周知,使用SPSecurity.RunWithElevatedPrivileges(delegate(){})进行运行的时候是以应用程序池账号运行,可以尝试在代码中通过HttpContext.Current.User.Identity.Name来获取当前运行账号详情(未经测试,请自行确认),通过SharePoint创建新的Web应用程序的时候,SharePoint会自动为该账号添加以下权限:

       引用自http://technet.microsoft.com/en-us/library/cc678863.aspx#Section3

    Application pool account
    The application pool account is used for application pool identity. The application pool account requires the following permission configuration settings:

    The following machine-level permission is configured automatically: The application pool account is a member of WSS_WPG.

    The following SQL Server and database permissions for this account are configured automatically:

    The application pool accounts for Web applications are assigned to the db_owner role for the content databases.
    This account is assigned to the WSS_CONTENT_APPLICATION_POOLS role associated with the farm configuration database.
    This account is assigned to the WSS_CONTENT_APPLICATION_POOLS role associated with the SharePoint_Admin content database.

     2.启动工作流权限需要具有Edit Item权限,如果在通过SharePoint Designer开发的工作流中指定需要Manage List权限的则需要有相应权限

    最后正常运行使用的代码:

    public static bool IsAdmin(WorkflowContext context, string listId, int itemId, string userName)
    {
                SPWorkflowActivationProperties properties = new SPWorkflowActivationProperties();
                bool rtnVal = false;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(context.Site.Url))
                    {
                       
                //SPWeb web = context.Web;
                        SPWeb web = site.RootWeb;
                        SPUserCollection users = web.SiteAdministrators;
                        foreach (SPUser user in users)
                        {
                            if (user.LoginName == userName)
                            {
                                rtnVal = true;
                                break;
                            }
                        }
                    }
                });
                return rtnVal;
    }
    

    最开始通过context.Web来获取站点对象,然后通过返回的web对象来获取SiteAdministrators属性,通过Visual Studio调试时发现运行到此处会报非授权操作错误,查看web对象发现其中的currentUser属性并不是应用程序池的账号,说明即便提权过后,web仍然使用的时从context中过来的当前登录用户身份,改为创建自定义的SPSite对象后问题解决。

  • 相关阅读:
    .net 加伪静态的方法
    前台调用后台事件的方法
    关于一个网站的源码问题
    div里面有ul li时 让高度自适应的方法
    用insert语句写入汉字变成问号的解决
    .net 4.0 ValidateRequest="false" 无效
    修复 VS2008 asp.net 设计视图 失效/工具选项[Html设计视图]出现"加载此属性页时出错" 方案
    绑定数据时,时间格式的转换
    IE下CSS属性float:right下移换行或不显示的问题原因及解决
    珍惜生命,远离培训 《如何选择好的培训机构》读后感 JavaEye技术网站
  • 原文地址:https://www.cnblogs.com/johnsonwong/p/2107924.html
Copyright © 2011-2022 走看看