本文整理汇总了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);
}
示例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);
}