惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
aimingoo的专栏
aimingoo的专栏
C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
C
CERT Recently Published Vulnerability Notes
T
Tailwind CSS Blog
腾讯CDC
罗磊的独立博客
Security Latest
Security Latest
K
Kaspersky official blog
A
Arctic Wolf
博客园 - Franky
D
Docker
博客园 - 司徒正美
GbyAI
GbyAI
T
Tenable Blog
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
H
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
小众软件
小众软件
V
V2EX
T
Threatpost
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
S
Securelist
Google DeepMind News
Google DeepMind News
I
Intezer
The Register - Security
The Register - Security
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
C
Cisco Blogs
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
S
Schneier on Security
Scott Helme
Scott Helme
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
L
LangChain Blog
P
Proofpoint News Feed

博客园 - ◎寶☆呗

Sharepoint 自定义字段(栏) 动态获取数据 Sharepoint 工具使用总结 Sharepoint 内存泄漏 检测工具+-- Extjs 中的tbar中的事件 winform Tab键循序 小发现 instsrv.exe——来自Windows 2000 Resource Kits的一个小工具 [转载]MOSS 2007 SP1 stsadm 194 条指令 (用命令行部署infopath Form )Deploy administrator-approved form templates using command line sharepoint计时器(定时发邮件) Infopath开发经验(xml数据) 基本活动:CodeActivity Creating a Custom SharePoint 2007 List Definition Create a New SharePoint Permission Level and Bind it to an Existing SharePoint Group 执行带返回参数的存储过程 Sorry.....Sorry..... 操作Infopath中的XMl C#编程规范<二> C#代码规范. 工作需要养成的习惯(个人经验)
通过Sharepoint扩展的Webserives来获取某一权限是是否存在
◎寶☆呗 · 2008-01-17 · via 博客园 - ◎寶☆呗

在Form认证的网站下,我们要判断我们添加的权限是否存在.可以用下面的方法:

 1
 2protected bool GetPermissions_Groups(string permissionsName)
 3        {
 4            try 
 5            {
 6               string username = Context.User.Identity.Name;
 7               PermissionsMoss.Permissions permService = new PermissionsMoss.Permissions();
 8               permService.Url = SPControl.GetContextWeb(Context).Url + "/_vti_bin/Permissions.asmx";
                    
 9               System.Net.Cookie authCookie = GenerateFormsAuthenticationCookie.GetCookie(ConfigurationManager.AppSettings["username"], ConfigurationManager.AppSettings["userpass"]);
10               permService.CookieContainer = new CookieContainer();
11               permService.CookieContainer.Add(authCookie);
12               XmlNode ndPermissions = permService.GetPermissionCollection(SPControl.GetContextWeb(Context).Url, "Web");
13
14               XmlNodeList xnl = ndPermissions.ChildNodes;
15
16               if (xnl == nullreturn false;
17               foreach (XmlNode xn in xnl)
18               {
19                   if (xn != null)
20                   {
21                       XmlNodeList xnl_permission = xn.ChildNodes;
22
23                       foreach (XmlNode xn_permission in xnl_permission)
24                       {
25                           if (xnl_permission != null)
26                           {
27                               if (xn_permission.Attributes["MemberIsUser"].Value != "True")
28                               {
29                                   if (xn_permission.Attributes["GroupName"].Value == permissionsName)
30                                   {
31                                       return true;
32                                   }

33                               }

34
35                           }

36                       }

37
38                   }

39                 
40               }

41               return false;
42            }

43            catch(Exception ex)
44            {
45                return false;
46            }

47          
48
49        }

50

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using GetPermissionsAndGroups.FormsLogin;
// FormsLogin是添加的Form 模拟登陆引用的asmx的文件夹名字
//GetPermissionsAndGroups是这个webpart的命名空间
/// <summary>
/// Summary description for GenerateFormsAuthenticationCookie
/// </summary>

public class GenerateFormsAuthenticationCookie
{
    
protected GenerateFormsAuthenticationCookie()
    
{
        
//
        
// TODO: Add constructor logic here
        
//
    }

    
public static Cookie GetCookie(string UserName, string Password)
    
{
        Authentication auth 
= new Authentication();
        auth.CookieContainer 
= new CookieContainer();
        LoginResult result 
= auth.Login(UserName, Password);
        
if (result.ErrorCode == LoginErrorCode.NoError)
        
{
            CookieCollection cookies 
= auth.CookieContainer.GetCookies(new Uri(auth.Url));
            Cookie authCookie 
= cookies[result.CookieName];
            
return authCookie;
        }

        
throw new Exception("403 Forbidden");
    }

}

当然可以不用Webservies 直接用代码:

添加一个组及其给一个组权限并给组添加用户:

  protected bool AddPermissions()
        
{
            
try
            
{
                SPSite sps 
= SPControl.GetContextSite(Context);
                SPWeb spw 
= sps.RootWeb;
                
for (int i = 0; i <= spw.RoleDefinitions.Count - 1; i++)
                
{
                    
if (spw.RoleDefinitions[i].Name == "Test_Example_last")
                    
{
                        
return false;
                    }

                }

                
string permissionLevelName = "Test_Example_last";
                
                SPRoleDefinition newPermissionlevel 
= new SPRoleDefinition();
                newPermissionlevel.Name 
= permissionLevelName;
                newPermissionlevel.Description 
= "Example Permission Level";
                newPermissionlevel.BasePermissions 
= SPBasePermissions.AddListItems| SPBasePermissions.EditListItems |
                    SPBasePermissions.ViewPages
|
                    SPBasePermissions.ViewVersions 
| SPBasePermissions.OpenItems | 
                    SPBasePermissions.ViewUsageData 
| SPBasePermissions.Open|
                    SPBasePermissions.BrowseUserInfo 
| SPBasePermissions.EditMyUserInfo |
                    SPBasePermissions.ManagePersonalViews ;
                
//add the permission level to web
                spw.AllowUnsafeUpdates = true;
                
                spw.RoleDefinitions.Add(newPermissionlevel);
                
// Bind to the permission level we just added
                newPermissionlevel = spw.RoleDefinitions[permissionLevelName];

              
                
//Create a new group
                SPGroupCollection collGroups = spw.SiteGroups;
                
for (int i = 0; i <= spw.SiteGroups.Count - 1; i++)
                
{
                    
if (collGroups[i].Name== "Test_Example_last")
                    
{
                        
return false;
                    }

                }


                SPMember oMember 
= spw.SiteUsers["Uers_name"];
                SPUser oUeser 
= spw.SiteUsers["User_name"];
                collGroups.Add(
"Test_Example_last", oMember, oUeser, "this is group is example");
                spw.SiteGroups[
"Test_Example_last"].AddUser(spw.SiteUsers["User_name"]);
                
                
// Create a new role Assignment using the SharePoint Group "Test_Example"
                SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)spw.SiteGroups["Test_Example_last"]);

                
// Add the Permission Level to the Test_Example SharePoint Group
                roleAssignment.RoleDefinitionBindings.Add(newPermissionlevel);
                
// Add the new Role Assignment to the web
                spw.RoleAssignments.Add(roleAssignment);
                
return true;
            }

            
catch (Exception ex)
            
{
                
return false;
            }


        }