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


C# EvaluationContext.TryGetIdentities方法代码示例

本文整理汇总了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;
        }
开发者ID:rag2111,项目名称:Hexa.Core,代码行数:59,代码来源:BaseX509AuthorizationPolicy.cs


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