Hugh Lins 的回答可能有效,但我并不完全满意。以下是一些有用的提示(使用 MS DLL 和 .NET API)。
IGroupSecurityService group_security_service; // declared deprecated
group_security_service = team_project_collection.GetService<IGroupSecurityService>();
...
// create group
group_security_service.CreateApplicationGroup(prjinfo.Uri, sGroupName, sGroupDescription);
...
提取我们需要的组(即贡献者)的权限:
- 组的IdentityDescriptor
- 每个使用的安全命名空间的安全令牌
1.IdentityDescriptor
TeamFoundationIdentity tfs_id = identity_management_service.ReadIdentity(IdentitySearchFactor.LocalGroupName,sGroup, MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource);
var desc = tfs_id.Descriptor
2.Token示例在这里:
https://docs.microsoft.com/en-us/azure/devops/cli/security_tokens
我们必须创建一个依赖于使用的安全命名空间的字符串。
var securityNamespaces = securityService.GetSecurityNamespaces();
对于每个安全命名空间,令牌的格式都略有不同。
例如对于“项目”命名空间:
$PROJECT:vstfs:///Classification/TeamProject/xxxxxxxx-a1de-4bc8-b751-188eea17c3ba'
vstfs:///...-Uri 来自这里:
prjinfo = common_structure_service4.GetProjectFromName(sTeamProject);
--> prjinfo.Uri
为了调用 QueryAccessControlList,我们需要描述符作为数组参数:
IdentityDescriptor[] tfidDescriptors = new IdentityDescriptor[] {desc};
调用 QueryAccessControlList:
foreach (var secNS in securityNamespaces)
{
string sToken = CreateToken(secNS.Description.NamespaceId);
AccessControlList acl = secNS.QueryAccessControlList(sToken, tfidDescriptors, false);
foreach (var ace in acl.AccessControlEntries)
{
ace.Allow vs. ace.Deny contain bit coded permissions
}
}
稍后我们可以将权限设置给另一个组。
(我们必须将 INHERIT 和 ALLOW/DENY 分开)。
示例:
...
secNS.RemovePermissions(sToken, desc, inherits);
...
secNS.SetPermissions(sToken, desc, allows, denies, true);
干杯。