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


C# MultiDictionary.Get方法代码示例

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


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

示例1: ReportPermissions

        /// <summary>
        /// Reporting is done in a function that returns a string, to avoid any performance impact when the trace log is not enabled.
        /// </summary>
        private string ReportPermissions(IUserInfo userInfo, PrincipalInfo principal, Lazy<IDictionary<Guid, string>> roleNamesIndex,
            IEnumerable<Permission> userPermissions, IEnumerable<ClaimInfo> claims, IEnumerable<bool> userHasClaims)
        {
            var report = new List<string>();

            // Create an index of permissions:

            var permissionsByClaim = new MultiDictionary<Guid, Permission>();
            foreach (var permission in userPermissions)
                permissionsByClaim.Add(permission.ClaimID, permission);

            // Analyze permissions for required claims:

            foreach (var claimResult in claims.Zip(userHasClaims, (Claim, UserHasIt) => new { Claim, UserHasIt }))
            {
                var claimPermissions = claimResult.Claim.ID != null
                    ? permissionsByClaim.Get(claimResult.Claim.ID.Value)
                    : new Permission[] { };

                var permissionsDescription = claimPermissions
                    .Select(permission => new
                        {
                            permission.IsAuthorized,
                            PrincipalOrRoleName = permission.PrincipalID != null
                                ? ("principal " + (permission.PrincipalID.Value == principal.ID ? principal.Name : permission.PrincipalID.Value.ToString()))
                                : ("role " + GetRoleNameSafe(permission.RoleID.Value, roleNamesIndex))
                        })
                    .ToList();

                var allowedFor = permissionsDescription.Where(p => p.IsAuthorized).Select(p => p.PrincipalOrRoleName).ToList();
                var deniedFor = permissionsDescription.Where(p => !p.IsAuthorized).Select(p => p.PrincipalOrRoleName).ToList();

                string explanation = "User " + userInfo.UserName + " " + (claimResult.UserHasIt ? "has" : "doesn't have")
                    + " claim '" + claimResult.Claim.Resource + " " + claimResult.Claim.Right + "'. It is ";

                if (deniedFor.Count != 0)
                    if (allowedFor.Count != 0)
                        explanation += "denied for " + string.Join(", ", deniedFor) + " and allowed for " + string.Join(", ", allowedFor) + " (deny overrides allow).";
                    else
                        explanation += "denied for " + string.Join(", ", deniedFor) + ".";
                else
                    if (allowedFor.Count != 0)
                        explanation += "allowed for " + string.Join(", ", allowedFor) + ".";
                    else
                        if (claimResult.Claim.ID == null)
                            explanation += "denied by default (the claim does not exist or is no longer active).";
                        else
                            explanation += "denied by default (no permissions defined).";

                report.Add(explanation);
            }

            return string.Join("\r\n", report);
        }
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:57,代码来源:CommonAuthorizationProvider.cs

示例2: ReportPermissions

        private string ReportPermissions(IUserInfo userInfo, IList<IPermissionBrowse> userPermissions, IList<Claim> requiredClaims)
        {
            // Reporting is done in a function that returns string, to avoid any performance impact when the trace log is not enabled.

            var report = new List<string>();

            var permissionsByClaim = new MultiDictionary<string, IPermissionBrowse>();
            foreach (var permission in userPermissions)
                permissionsByClaim.Add(permission.ClaimResource + "." + permission.ClaimRight, permission);

            foreach (var claim in requiredClaims)
            {
                string claimName = claim.FullName;
                var claimPermissions = permissionsByClaim.Get(claimName);
                var allowedForRoles = claimPermissions.Where(p => p.IsAuthorized.Value).Select(p => p.Principal).ToList();
                var deniedForRoles = claimPermissions.Where(p => !p.IsAuthorized.Value).Select(p => p.Principal).ToList();

                if (deniedForRoles.Count != 0)
                    if (allowedForRoles.Count != 0)
                        report.Add("User " + userInfo.UserName + " claim '" + claimName + "' is denied for role " + string.Join(", ", deniedForRoles) + " and allowed for role " + string.Join(", ", allowedForRoles) + " (deny overrides allow).");
                    else
                        report.Add("User " + userInfo.UserName + " claim '" + claimName + "' is denied for role " + string.Join(", ", deniedForRoles) + ".");
                else
                    if (allowedForRoles.Count != 0)
                        report.Add("User " + userInfo.UserName + " claim '" + claimName + "' is allowed for role " + string.Join(", ", allowedForRoles) + ".");
                    else
                        report.Add("User " + userInfo.UserName + " claim '" + claimName + "' is denied by default (no permissions defined).");
            }

            return string.Join("\r\n", report);
        }
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:31,代码来源:SimpleWindowsAuthorizationProvider.cs


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