Bewerken

Share via


ServiceCredentialsSecurityTokenManager.CreateSecurityTokenAuthenticator Method

Definition

Creates a security token authenticator based on the SecurityTokenRequirement.

public:
 override System::IdentityModel::Selectors::SecurityTokenAuthenticator ^ CreateSecurityTokenAuthenticator(System::IdentityModel::Selectors::SecurityTokenRequirement ^ tokenRequirement, [Runtime::InteropServices::Out] System::IdentityModel::Selectors::SecurityTokenResolver ^ % outOfBandTokenResolver);
public override System.IdentityModel.Selectors.SecurityTokenAuthenticator CreateSecurityTokenAuthenticator (System.IdentityModel.Selectors.SecurityTokenRequirement tokenRequirement, out System.IdentityModel.Selectors.SecurityTokenResolver outOfBandTokenResolver);
override this.CreateSecurityTokenAuthenticator : System.IdentityModel.Selectors.SecurityTokenRequirement * SecurityTokenResolver -> System.IdentityModel.Selectors.SecurityTokenAuthenticator
Public Overrides Function CreateSecurityTokenAuthenticator (tokenRequirement As SecurityTokenRequirement, ByRef outOfBandTokenResolver As SecurityTokenResolver) As SecurityTokenAuthenticator

Parameters

tokenRequirement
SecurityTokenRequirement

The security token requirement.

outOfBandTokenResolver
SecurityTokenResolver

When this method returns, contains a SecurityTokenResolver. This parameter is passed uninitialized.

Returns

The security token authenticator.

Exceptions

tokenRequirement is null.

A security token authenticator cannot be created for the tokenRequirement that was passed in.

Examples

The following code is an example of how to override this method.

internal class MyServiceCredentialsSecurityTokenManager :
    ServiceCredentialsSecurityTokenManager
{
    ServiceCredentials credentials;
    public MyServiceCredentialsSecurityTokenManager(ServiceCredentials credentials)
        : base(credentials)
    {
        this.credentials = credentials;
    }

    public override SecurityTokenAuthenticator CreateSecurityTokenAuthenticator
        (SecurityTokenRequirement tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver)
    {
        // Return your implementation of the SecurityTokenProvider based on the
        // tokenRequirement argument.
        SecurityTokenAuthenticator result;
        if (tokenRequirement.TokenType == SecurityTokenTypes.UserName)
        {
            MessageDirection direction = tokenRequirement.GetProperty<MessageDirection>
                (ServiceModelSecurityTokenRequirement.MessageDirectionProperty);
            if (direction == MessageDirection.Input)
            {
                outOfBandTokenResolver = null;
                result = new MySecurityTokenAuthenticator();
            }
            else
            {
                result = base.CreateSecurityTokenAuthenticator(tokenRequirement, out outOfBandTokenResolver);
            }
        }
        else
        {
            result = base.CreateSecurityTokenAuthenticator(tokenRequirement, out outOfBandTokenResolver);
        }

        return result;
    }
}
Friend Class MyServiceCredentialsSecurityTokenManager
    Inherits ServiceCredentialsSecurityTokenManager

    Private credentials As ServiceCredentials

    Public Sub New(ByVal credentials As ServiceCredentials)
        MyBase.New(credentials)
        Me.credentials = credentials
    End Sub

    Public Overrides Function CreateSecurityTokenAuthenticator(ByVal tokenRequirement As SecurityTokenRequirement, _
                                                               <System.Runtime.InteropServices.Out()> _
                                                               ByRef outOfBandTokenResolver _
                                                               As SecurityTokenResolver) As SecurityTokenAuthenticator
        ' Return your implementation of the SecurityTokenProvider based on the 
        ' tokenRequirement argument.
        Dim result As SecurityTokenAuthenticator
        If tokenRequirement.TokenType = SecurityTokenTypes.UserName Then
            Dim direction = tokenRequirement.GetProperty(Of MessageDirection)(ServiceModelSecurityTokenRequirement.MessageDirectionProperty)
            If direction = MessageDirection.Input Then
                outOfBandTokenResolver = Nothing
                result = New MySecurityTokenAuthenticator()
            Else
                result = MyBase.CreateSecurityTokenAuthenticator(tokenRequirement, _
                                                                 outOfBandTokenResolver)
            End If
        Else
            result = MyBase.CreateSecurityTokenAuthenticator(tokenRequirement, _
                                                             outOfBandTokenResolver)
        End If

        Return result
    End Function

End Class

Remarks

An outOfBand token resolver can optionally be returned by the method, which is used by the WCF security processor to resolve tokens that are not in the SOAP message when processing security. The SecurityTokenAuthenticator that is returned by this method validates tokens and extracts claims. One SecurityTokenAuthenticator is created for each class derived from ServiceModelSecurityTokenRequirement.

Applies to