ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée un fournisseur de jetons de sécurité basé sur la SecurityTokenRequirement.
public:
override System::IdentityModel::Selectors::SecurityTokenProvider ^ CreateSecurityTokenProvider(System::IdentityModel::Selectors::SecurityTokenRequirement ^ requirement);
public override System.IdentityModel.Selectors.SecurityTokenProvider CreateSecurityTokenProvider (System.IdentityModel.Selectors.SecurityTokenRequirement requirement);
override this.CreateSecurityTokenProvider : System.IdentityModel.Selectors.SecurityTokenRequirement -> System.IdentityModel.Selectors.SecurityTokenProvider
Public Overrides Function CreateSecurityTokenProvider (requirement As SecurityTokenRequirement) As SecurityTokenProvider
Paramètres
- requirement
- SecurityTokenRequirement
L’exigence du jeton de sécurité.
Retours
Fournisseur de jetons de sécurité.
Exceptions
requirement
a la valeur null
.
Il est impossible de créer un fournisseur de jetons de sécurité pour le paramètre requirement
qui a été passé.
Exemples
L'exemple de code suivant montre comment substituer cette méthode.
internal class MyServiceCredentialsSecurityTokenManager :
ServiceCredentialsSecurityTokenManager
{
MyServiceCredentials credentials;
public MyServiceCredentialsSecurityTokenManager(
MyServiceCredentials 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.Input)
{
if (requirement.KeyUsage == SecurityKeyUsage.Exchange)
{
result = new X509SecurityTokenProvider(
credentials.ServiceEncryptingCertificate);
}
else
{
result = new X509SecurityTokenProvider(
credentials.ClientSigningCertificate);
}
}
else
{
if (requirement.KeyUsage == SecurityKeyUsage.Signature)
{
result = new X509SecurityTokenProvider(
credentials.ServiceSigningCertificate);
}
else
{
result = new X509SecurityTokenProvider(
credentials.ClientEncryptingCertificate);
}
}
}
else
{
result = base.CreateSecurityTokenProvider(requirement);
}
return result;
}
}
Friend Class MyServiceCredentialsSecurityTokenManager
Inherits ServiceCredentialsSecurityTokenManager
Private credentials As MyServiceCredentials
Public Sub New(ByVal credentials As MyServiceCredentials)
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.Input Then
If requirement.KeyUsage = SecurityKeyUsage.Exchange Then
result = New X509SecurityTokenProvider(credentials.ServiceEncryptingCertificate)
Else
result = New X509SecurityTokenProvider(credentials.ClientSigningCertificate)
End If
Else
If requirement.KeyUsage = SecurityKeyUsage.Signature Then
result = New X509SecurityTokenProvider(credentials.ServiceSigningCertificate)
Else
result = New X509SecurityTokenProvider(credentials.ClientEncryptingCertificate)
End If
End If
Else
result = MyBase.CreateSecurityTokenProvider(requirement)
End If
Return result
End Function
End Class
Remarques
La classe SecurityTokenProvider est chargée d'obtenir des jetons pour une ServiceModelSecurityTokenRequirementdonnée. Les fournisseurs de jetons peuvent également, de manière facultative, prendre en charge des jetons de renouvellement et d'annulation. Le fournisseur de jetons peut mettre en cache des jetons s'il est configuré de manière adéquate.