다음을 통해 공유


ClientCredentialsSecurityTokenManager.CreateSecurityTokenProvider 메서드

정의

보안 토큰 공급자를 만듭니다.

public:
 override System::IdentityModel::Selectors::SecurityTokenProvider ^ CreateSecurityTokenProvider(System::IdentityModel::Selectors::SecurityTokenRequirement ^ tokenRequirement);
public override System.IdentityModel.Selectors.SecurityTokenProvider CreateSecurityTokenProvider (System.IdentityModel.Selectors.SecurityTokenRequirement tokenRequirement);
override this.CreateSecurityTokenProvider : System.IdentityModel.Selectors.SecurityTokenRequirement -> System.IdentityModel.Selectors.SecurityTokenProvider
Public Overrides Function CreateSecurityTokenProvider (tokenRequirement As SecurityTokenRequirement) As SecurityTokenProvider

매개 변수

반환

SecurityTokenProvider

SecurityTokenProvider 개체

예외

tokenRequirement이(가) null인 경우

예제

다음 코드에서는 이 메서드를 재정의하는 방법을 보여 줍니다.

internal class MyClientCredentialsSecurityTokenManager :
    ClientCredentialsSecurityTokenManager
{
    MyClientCredentials credentials;

    public MyClientCredentialsSecurityTokenManager(
        MyClientCredentials credentials): base(credentials)
    {
        this.credentials = credentials;
    }

    public override SecurityTokenProvider CreateSecurityTokenProvider(
        SecurityTokenRequirement requirement)
    {
        SecurityTokenProvider result = null;
        if (requirement.TokenType == SecurityTokenTypes.X509Certificate)
        {
            MessageDirection direction = requirement.GetProperty
                <MessageDirection>(ServiceModelSecurityTokenRequirement.
                MessageDirectionProperty);
            if (direction == MessageDirection.Output)
            {
                if (requirement.KeyUsage == SecurityKeyUsage.Signature)
                {
                    result = new X509SecurityTokenProvider(
                        this.credentials.ClientSigningCertificate);
                }
                else
                {
                    result = new X509SecurityTokenProvider(this.credentials.
                        ServiceEncryptingCertificate);
                }
            }
            else
            {
                if (requirement.KeyUsage == SecurityKeyUsage.Signature)
                {
                    result = new X509SecurityTokenProvider(this.
                        credentials.ServiceSigningCertificate);
                }
                else
                {
                    result = new X509SecurityTokenProvider(credentials.
                        ClientEncryptingCertificate);
                }
            }
        }
        else
        {
            result = base.CreateSecurityTokenProvider(requirement);
        }

        return result;
    }

    public override SecurityTokenAuthenticator
        CreateSecurityTokenAuthenticator(SecurityTokenRequirement
        tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver)
    {
        return base.CreateSecurityTokenAuthenticator(tokenRequirement,
            out outOfBandTokenResolver);
    }
}
Friend Class MyClientCredentialsSecurityTokenManager
    Inherits ClientCredentialsSecurityTokenManager
    Private credentials As MyClientCredentials

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

    Public Overrides Function CreateSecurityTokenProvider(ByVal requirement As SecurityTokenRequirement) As SecurityTokenProvider
        Dim result As SecurityTokenProvider = Nothing
        If requirement.TokenType = SecurityTokenTypes.X509Certificate Then
            Dim direction As MessageDirection = requirement.GetProperty (Of MessageDirection)(ServiceModelSecurityTokenRequirement. MessageDirectionProperty)
            If direction = MessageDirection.Output Then
                If requirement.KeyUsage = SecurityKeyUsage.Signature Then
                    result = New X509SecurityTokenProvider(Me.credentials.ClientSigningCertificate)
                Else
                    result = New X509SecurityTokenProvider(Me.credentials. ServiceEncryptingCertificate)
                End If
            Else
                If requirement.KeyUsage = SecurityKeyUsage.Signature Then
                    result = New X509SecurityTokenProvider(Me. credentials.ServiceSigningCertificate)
                Else
                    result = New X509SecurityTokenProvider(credentials. ClientEncryptingCertificate)
                End If
            End If
        Else
            result = MyBase.CreateSecurityTokenProvider(requirement)
        End If

        Return result
    End Function

    Public Overrides Function CreateSecurityTokenAuthenticator(ByVal tokenRequirement As SecurityTokenRequirement, <System.Runtime.InteropServices.Out()> ByRef outOfBandTokenResolver As SecurityTokenResolver) As SecurityTokenAuthenticator
        Return MyBase.CreateSecurityTokenAuthenticator(tokenRequirement, outOfBandTokenResolver)
    End Function
End Class

설명

SecurityTokenProvider 클래스는 지정된 ServiceModelSecurityTokenRequirement에 맞는 토큰을 가져옵니다. 필요한 경우 토큰 공급자는 토큰 갱신과 취소도 지원합니다.

적용 대상