ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Crea un proveedor de tokens de seguridad basado en 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
Parámetros
- requirement
- SecurityTokenRequirement
El requisito del token de seguridad.
Devoluciones
Proveedor de tokens de seguridad.
Excepciones
requirement
es null
.
No se puede crear un proveedor de tokens de seguridad para elrequirement
que se pasó.
Ejemplos
El siguiente código muestra cómo invalidar este método.
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
Comentarios
La clase SecurityTokenProvider es responsable de obtener los tokens para un ServiceModelSecurityTokenRequirement determinado. Opcionalmente, los proveedores de token pueden permitir la renovación y también la cancelación de los tokens. El proveedor de token puede almacenar en memoria caché los tokens si se configura para ello.