本文整理汇总了C#中System.IdentityModel.Policy.EvaluationContext.TryGetIdentities方法的典型用法代码示例。如果您正苦于以下问题:C# EvaluationContext.TryGetIdentities方法的具体用法?C# EvaluationContext.TryGetIdentities怎么用?C# EvaluationContext.TryGetIdentities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IdentityModel.Policy.EvaluationContext
的用法示例。
在下文中一共展示了EvaluationContext.TryGetIdentities方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
/// <summary>
/// Evaluates whether a user meets the requirements for this authorization policy.
/// </summary>
/// <param name="evaluationContext">An <see cref="T:System.IdentityModel.Policy.EvaluationContext"/> that contains the claim set that the authorization policy evaluates.</param>
/// <param name="state">A <see cref="T:System.Object"/>, passed by reference that represents the custom state for this authorization policy.</param>
/// <returns>
/// false if the <see cref="M:System.IdentityModel.Policy.IAuthorizationPolicy.Evaluate(System.IdentityModel.Policy.EvaluationContext,[email protected])"/> method for this authorization policy must be called if additional claims are added by other authorization policies to <paramref name="evaluationContext"/>; otherwise, true to state no additional evaluation is required by this authorization policy.
/// </returns>
public override bool Evaluate(EvaluationContext evaluationContext, ref object state)
{
IList<IIdentity> identities = evaluationContext.TryGetIdentities();
// Sleep no identities found yet.
if (identities == null || identities.Count == 0)
{
_Log.Debug("identities == null or identities.Count == 0; sleeping..");
return false;
}
// Sleep no identities of type X509.
if (!identities.Any(i => i.AuthenticationType == "X509"))
{
_Log.Debug("No identity authenticated by X509 certificate; sleeping..");
return false;
}
if (state == null)
{
state = 0;
}
else
{
state = (int)state + 1;
}
// Should not evaluate policy twice.
if ((int)state > 0)
{
return true;
}
X509Certificate2 certificate = GetClientCertificate(evaluationContext);
if (certificate == null)
{
_Log.Debug("No valid X509CertificateClaimSet was found.");
return true;
}
IPrincipal principal = GetPrincipal(evaluationContext, certificate);
if (principal == null)
{
_Log.Warn("User not authorized.");
return true;
}
SetupEvaluationContext(evaluationContext, principal);
return true;
}