当前位置: 首页>>代码示例>>C#>>正文


C# ISecurityService.GetSecurityNamespace方法代码示例

本文整理汇总了C#中ISecurityService.GetSecurityNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# ISecurityService.GetSecurityNamespace方法的具体用法?C# ISecurityService.GetSecurityNamespace怎么用?C# ISecurityService.GetSecurityNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISecurityService的用法示例。


在下文中一共展示了ISecurityService.GetSecurityNamespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractBuildPermissions

        /////// <summary>
        /////// Extracts work item permissions for a specific identity
        /////// </summary>
        /////// <param name="server">Server security service</param>
        /////// <param name="projectSecurityToken">Project Security Token</param>
        /////// <param name="userIdentity">User identity</param>
        /////// <returns>The list of the permissions</returns>
        ////private static List<Permission> ExtractWorkItemsPermissions(
        ////    ISecurityService server,
        ////    string projectSecurityToken,
        ////    TeamFoundationIdentity userIdentity)
        ////{
        ////    var result = new List<Permission>();
        ////    SecurityNamespace workItemsSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(PermissionScope.WorkItemAreas, server));
        ////    if (workItemsSecurityNamespace != null)
        ////    {
        ////        Console.WriteLine("== Extract WorkItems Permissions ==");
        ////        AccessControlList workItemsAccessList = workItemsSecurityNamespace.QueryAccessControlList(
        ////            projectSecurityToken,
        ////            new List<IdentityDescriptor> { userIdentity.Descriptor },
        ////            true);
        ////        string allowedWorkItemPermissions = string.Empty;
        ////        string denyWorkItemPermissions = string.Empty;
        ////        foreach (AccessControlEntry ace in workItemsAccessList.AccessControlEntries)
        ////        {
        ////            if (0 != ace.Allow)
        ////            {
        ////                allowedWorkItemPermissions = ((QueryItemPermissions)ace.Allow).ToString();
        ////                result.AddRange(
        ////                    Helpers.GetActionDetailsByName(allowedWorkItemPermissions, "Allow", PermissionScope.WorkItemAreas));
        ////            }

        ////            if (0 != ace.Deny)
        ////            {
        ////                denyWorkItemPermissions = ((QueryItemPermissions)ace.Deny).ToString();
        ////                result.AddRange(
        ////                    Helpers.GetActionDetailsByName(denyWorkItemPermissions, "Deny", PermissionScope.WorkItemAreas));
        ////            }
        ////        }
        ////    }

        ////    return result;
        ////}
        
        /// <summary>
        /// Extracts build permissions for a specific identity.
        /// </summary>
        /// <param name="server">Server security service</param>
        /// <param name="projectSecurityToken">Project Security Token</param>
        /// <param name="userIdentity">User identity</param>
        /// <returns>The list of the permissions</returns>
        private static List<Permission> ExtractBuildPermissions(ISecurityService server, string projectSecurityToken, TeamFoundationIdentity userIdentity)
        {
            var result = new List<Permission>();
            SecurityNamespace buildSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(PermissionScope.TeamBuild, server));
            Console.WriteLine("== Extract Build Permissions ==");
            AccessControlList buildAccessList = buildSecurityNamespace.QueryAccessControlList(
                projectSecurityToken,
                new List<IdentityDescriptor> { userIdentity.Descriptor },
                true);

            foreach (AccessControlEntry ace in buildAccessList.AccessControlEntries)
            {
                if (0 != ace.Allow)
                {
                    var allowedBuildPermissions = ((EnumrationsList.BuildPermissions)ace.Allow).ToString();
                    result.AddRange(
                        Helpers.GetActionDetailsByName(allowedBuildPermissions, "Allow", PermissionScope.TeamBuild));
                }

                if (0 != ace.Deny)
                {
                    var denyBuildPermissions = ((EnumrationsList.BuildPermissions)ace.Deny).ToString();
                    result.AddRange(
                        Helpers.GetActionDetailsByName(denyBuildPermissions, "Deny", PermissionScope.TeamBuild));
                }
            }

            return result;
        }
开发者ID:modulexcite,项目名称:Extracting-effective-permissions-from-TFS,代码行数:80,代码来源:Program.cs

示例2: ExtractGitVersionControlPermissions

        /// <summary>
        /// Sample method on how to extracts the git version control permissions.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="groups">The groups.</param>
        /// <param name="userIdentity">The user identity.</param>
        /// <param name="projectSecurityToken">The project security token.</param>
        /// <param name="identityManagementService">The identityManagementService.</param>
        /// <param name="vcs">The VCS.</param>
        /// <param name="gitService">The git service.</param>
        /// <returns>List of Permissions</returns>
        private static List<Permission> ExtractGitVersionControlPermissions(ISecurityService server, IEnumerable<string> groups, TeamFoundationIdentity userIdentity, string projectSecurityToken, IIdentityManagementService identityManagementService, VersionControlServer vcs, TeamFoundation.Git.Client.GitRepositoryService gitService)
        {
            Console.WriteLine("== Extract Git Version Control Permissions ==");
            SecurityNamespace gitVersionControlSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(PermissionScope.GitSourceControl, server));
            var gitProjectRepoService = gitService.QueryRepositories(projectSecurityToken);
            
            // This sample handle only the default repository, you can iterate through all repositories same way
            var defaultGitRepo = gitProjectRepoService.SingleOrDefault(gr => gr.Name.Equals(projectSecurityToken));

            vcs.TryGetTeamProject(projectSecurityToken);
            if (defaultGitRepo == null)
            {
                return new List<Permission>();
            }

            // Repository Security Token is repoV2/TeamProjectId/RepositoryId
            var repoIdToken = string.Format("repoV2{0}{1}{2}{3}", gitVersionControlSecurityNamespace.Description.SeparatorValue, defaultGitRepo.ProjectReference.Id, gitVersionControlSecurityNamespace.Description.SeparatorValue, defaultGitRepo.Id);
            
            // vcs.GetTeamProject(projectSecurityToken);
            AccessControlList versionControlAccessList =
                gitVersionControlSecurityNamespace.QueryAccessControlList(
                    repoIdToken,
                    new List<IdentityDescriptor> { userIdentity.Descriptor },
                    true);
            var gitVersionControlPermissions = new List<Permission>();

            foreach (AccessControlEntry ace in versionControlAccessList.AccessControlEntries)
            {
                if (0 != ace.Allow)
                {
                    var allowedVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.Allow).ToString();
                    gitVersionControlPermissions.AddRange(
                        Helpers.GetActionDetailsByName(allowedVersionControlPermissions, "Allow", PermissionScope.GitSourceControl));
                }

                if (0 != ace.Deny)
                {
                    var denyVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.Deny).ToString();
                    gitVersionControlPermissions.AddRange(
                        Helpers.GetActionDetailsByName(denyVersionControlPermissions, "Deny", PermissionScope.GitSourceControl));
                }
            }

            if (gitVersionControlPermissions.Count == 0)
            {
                foreach (AccessControlEntry ace in versionControlAccessList.AccessControlEntries)
                {
                    if (0 != ace.ExtendedInfo.EffectiveAllow)
                    {
                        var allowedVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.ExtendedInfo.EffectiveAllow).ToString();
                        gitVersionControlPermissions.AddRange(
                            Helpers.GetActionDetailsByName(allowedVersionControlPermissions, "Allow", PermissionScope.GitSourceControl));
                    }

                    if (0 != ace.ExtendedInfo.EffectiveDeny)
                    {
                        var denyVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.ExtendedInfo.EffectiveDeny).ToString();
                        gitVersionControlPermissions.AddRange(
                            Helpers.GetActionDetailsByName(denyVersionControlPermissions, "Deny", PermissionScope.GitSourceControl));
                    }
                }
            }

            foreach (string group in groups)
            {
                TeamFoundationIdentity groupIdentity = identityManagementService.ReadIdentity(IdentitySearchFactor.Identifier, group, MembershipQuery.None, ReadIdentityOptions.IncludeReadFromSource);

                AccessControlList groupAccessList =
              gitVersionControlSecurityNamespace.QueryAccessControlList(
               repoIdToken,
                  new List<IdentityDescriptor> { groupIdentity.Descriptor },
                  true);

                foreach (AccessControlEntry ace in groupAccessList.AccessControlEntries)
                {
                    if (0 != ace.Allow)
                    {
                        var allowedPermissions = ((EnumrationsList.GitPermissions)ace.Allow).ToString();
                        var permissionsList = Helpers.GetActionDetailsByName(allowedPermissions, "Inherited Allow", PermissionScope.GitSourceControl);
                        Helpers.AppendGroupInheritanceInformation(permissionsList, groupIdentity.DisplayName);
                        gitVersionControlPermissions.AddRange(permissionsList);
                    }

                    if (0 != ace.Deny)
                    {
                        var denyPermissions = ((EnumrationsList.GitPermissions)ace.Deny).ToString();
                        var permissionsList = Helpers.GetActionDetailsByName(denyPermissions, "Inherited Deny", PermissionScope.GitSourceControl);
                        Helpers.AppendGroupInheritanceInformation(permissionsList, groupIdentity.DisplayName);
                        gitVersionControlPermissions.AddRange(permissionsList);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:Extracting-effective-permissions-from-TFS,代码行数:101,代码来源:Program.cs

示例3: ExtractGenericSecurityNamespacePermissions

        /// <summary>
        /// Extracts the generic security namespace permissions.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="permissionScope">The permission scope.</param>
        /// <param name="userIdentity">The user identity.</param>
        /// <param name="securityToken">The security token.</param>
        /// <param name="identityManagementService">The identityManagementService.</param>
        /// <param name="groups">The groups.</param>
        /// <returns>List of Permissions</returns>
        private static List<Permission> ExtractGenericSecurityNamespacePermissions(ISecurityService server, PermissionScope permissionScope, TeamFoundationIdentity userIdentity, string securityToken, IIdentityManagementService identityManagementService, IEnumerable<string> groups)
        {
            SecurityNamespace genericSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(permissionScope, server));
            AccessControlList userAccessList =
                genericSecurityNamespace.QueryAccessControlList(
                    securityToken,
                    new List<IdentityDescriptor> { userIdentity.Descriptor },
                    true);
            var result = new List<Permission>();
            result.AddRange(Helpers.AccessControlEntryToPermission(genericSecurityNamespace, userAccessList.AccessControlEntries, false, string.Empty));

            // handle group inheritance 
            foreach (string group in groups)
            {
                TeamFoundationIdentity groupIdentity = identityManagementService.ReadIdentity(IdentitySearchFactor.Identifier, group, MembershipQuery.None, ReadIdentityOptions.IncludeReadFromSource);

                AccessControlList groupAccessList =
                    genericSecurityNamespace.QueryAccessControlList(
                        securityToken,
                        new List<IdentityDescriptor> { groupIdentity.Descriptor },
                        true);
                result.AddRange(Helpers.AccessControlEntryToPermission(genericSecurityNamespace, groupAccessList.AccessControlEntries, true, groupIdentity.DisplayName));
            }

            var modifiedPermissions = Helpers.RemoveDuplicatePermissionsAndCombineGroups(result);
            return modifiedPermissions;
        }
开发者ID:modulexcite,项目名称:Extracting-effective-permissions-from-TFS,代码行数:37,代码来源:Program.cs


注:本文中的ISecurityService.GetSecurityNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。