ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
根據 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
參數
- requirement
- SecurityTokenRequirement
安全性權杖的需求。
傳回
安全性權杖提供者。
例外狀況
requirement
為 null
。
無法為傳入的 requirement
建立安全性權杖提供者。
範例
下列程式碼將示範如何覆寫這個方法。
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
備註
SecurityTokenProvider 類別會負責取得指定之 ServiceModelSecurityTokenRequirement 的權杖。 此外,權杖提供者也可以支援更新和取消權杖。 權杖提供者可以快取權杖 (如果設定這樣做的話)。