Share via


IAuthorizationPolicy.Evaluate(EvaluationContext, Object) Yöntem

Tanım

Kullanıcının bu yetkilendirme ilkesi gereksinimlerini karşılayıp karşılamadığını değerlendirir.

public:
 bool Evaluate(System::IdentityModel::Policy::EvaluationContext ^ evaluationContext, System::Object ^ % state);
public bool Evaluate (System.IdentityModel.Policy.EvaluationContext evaluationContext, ref object state);
abstract member Evaluate : System.IdentityModel.Policy.EvaluationContext * obj -> bool
Public Function Evaluate (evaluationContext As EvaluationContext, ByRef state As Object) As Boolean

Parametreler

evaluationContext
EvaluationContext

EvaluationContext Yetkilendirme ilkesinin değerlendirdiği talep kümesini içeren.

state
Object

ObjectBu yetkilendirme ilkesi için özel durumu temsil eden başvuru ile geçirilen bir .

Döndürülenler

false bu yetkilendirme ilkesinin yönteminin Evaluate(EvaluationContext, Object) , diğer yetkilendirme ilkeleri evaluationContexttarafından öğesine ek talepler eklendiğinde çağrılması gerekiyorsa; aksi takdirde, true bu yetkilendirme ilkesi tarafından ek değerlendirme gerekmediğini belirtmek için.

Örnekler

public bool Evaluate(EvaluationContext evaluationContext, ref object state)
{
    bool bRet = false;
    CustomAuthState customstate = null;

    // If state is null, then this method has not been called before, so
    // set up a custom state.
    if (state == null)
    {
        customstate = new CustomAuthState();
        state = customstate;
    }
    else
    {
        customstate = (CustomAuthState)state;
    }

    Console.WriteLine("Inside MyAuthorizationPolicy::Evaluate");

    // If claims have not been added yet...
    if (!customstate.ClaimsAdded)
    {
        // Create an empty list of Claims.
        IList<Claim> claims = new List<Claim>();

        // Iterate through each of the claim sets in the evaluation context.
        foreach (ClaimSet cs in evaluationContext.ClaimSets)
            // Look for Name claims in the current claim set.
            foreach (Claim c in cs.FindClaims(ClaimTypes.Name, Rights.PossessProperty))
                // Get the list of operations the given username is allowed to call.
                foreach (string s in GetAllowedOpList(c.Resource.ToString()))
                {
                    // Add claims to the list.
                    claims.Add(new Claim("http://example.org/claims/allowedoperation", s, Rights.PossessProperty));
                    Console.WriteLine("Claim added {0}", s);
                }

        // Add claims to the evaluation context.
        evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer,claims));

        // Record that claims have been added.
        customstate.ClaimsAdded = true;

        // Return true, which indicates this need not be called again.
        bRet = true;
    }
    else
    {
        // This point should not be reached, but just in case...
        bRet = true;
    }

    return bRet;
}
Public Function Evaluate(ByVal evaluationContext As EvaluationContext, _
     ByRef state As Object) As Boolean Implements IAuthorizationPolicy.Evaluate

    Dim bRet As Boolean = False
    Dim customstate As CustomAuthState = Nothing

    ' If state is null, then this method has not been called before, so 
    ' set up a custom state.
    If state Is Nothing Then
        customstate = New CustomAuthState()
        state = customstate
    Else
        customstate = CType(state, CustomAuthState)
    End If
    Console.WriteLine("Inside MyAuthorizationPolicy::Evaluate")

    ' If the claims have not been added yet...
    If Not customstate.ClaimsAdded Then
        ' Create an empty list of Claims
        Dim claims As New List(Of Claim)

        ' Iterate through each of the claimsets in the evaluation context.
        Dim cs As ClaimSet
        For Each cs In evaluationContext.ClaimSets
            ' Look for Name claims in the current claim set.
            Dim c As Claim
            For Each c In cs.FindClaims(ClaimTypes.Name, Rights.PossessProperty)
                ' Get the list of operations the given username is allowed to call.
                Dim s As String
                For Each s In GetAllowedOpList(c.Resource.ToString())

                    ' Add claims to the list
                    claims.Add(New Claim("http://example.org/claims/allowedoperation", _
                                s, Rights.PossessProperty))
                    Console.WriteLine("Claim added {0}", s)
                Next s
            Next c
        Next cs 
        
        ' Add claims to the evaluation context.
        evaluationContext.AddClaimSet(Me, New DefaultClaimSet(Me.Issuer, claims))

        ' Record that claims have been added.
        customstate.ClaimsAdded = True

        ' Return true, which indicates the method need not to be called again.
        bRet = True
    Else
        ' Should never get here, but just in case...
        bRet = True
    End If


    Return bRet

End Function 'Evaluate

Açıklamalar

Not

Arabirimi uygulayıcıları IAuthorizationPolicy yöntemin Evaluate farklı iş parçacıkları tarafından birden çok kez çağrılmasını beklemelidir.

Arabirimin uygulayıcıları yöntemine IAuthorizationPolicystate yapılan çağrılar arasındaki durumu izlemek için parametresini Evaluate kullanabilir. Yönteme Evaluate verilen bir çağrı içinde bir durum nesnesi ayarlanırsa, geçerli değerlendirme işleminde yöntemine yapılan her ve sonraki çağrıya Evaluate aynı nesne örneği geçirilir.

Şunlara uygulanır