.NET Framework Class Library
IAuthorizationPolicy..::.Evaluate Method

Evaluates whether a user meets the requirements for this authorization policy.

Namespace:  System.IdentityModel.Policy
Assembly:  System.IdentityModel (in System.IdentityModel.dll)
Syntax

Visual Basic (Declaration)
Function Evaluate ( _
    evaluationContext As EvaluationContext, _
    ByRef state As Object _
) As Boolean
Visual Basic (Usage)
Dim instance As IAuthorizationPolicy
Dim evaluationContext As EvaluationContext
Dim state As Object
Dim returnValue As Boolean

returnValue = instance.Evaluate(evaluationContext, _
    state)
C#
bool Evaluate(
    EvaluationContext evaluationContext,
    ref Object state
)
Visual C++
bool Evaluate(
    EvaluationContext^ evaluationContext, 
    Object^% state
)
JScript
function Evaluate(
    evaluationContext : EvaluationContext, 
    state : Object
) : boolean

Parameters

evaluationContext
Type: System.IdentityModel.Policy..::.EvaluationContext
An EvaluationContext that contains the claim set that the authorization policy evaluates.
state
Type: System..::.Object%
A Object, passed by reference that represents the custom state for this authorization policy.

Return Value

Type: System..::.Boolean
false if the Evaluate method for this authorization policy must be called if additional claims are added by other authorization policies to evaluationContext; otherwise, true to state no additional evaluation is required by this authorization policy.
Remarks

NoteNote:

Implementers of the IAuthorizationPolicy interface should expect the Evaluate method to be called multiple times by different threads.

Implementers of the IAuthorizationPolicy interface can use the state parameter to track state between calls to the Evaluate method. If a state object is set inside a given call to the Evaluate method, the same object instance is passed to each and every subsequent call to the Evaluate method in the current evaluation process.

Examples

Visual Basic
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
C#
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;
}
.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Page view tracker