當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。