ServiceCredentialsSecurityTokenManager.CreateSecurityTokenAuthenticator 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
根據 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
參數
- tokenRequirement
- SecurityTokenRequirement
安全性權杖的需求。
- outOfBandTokenResolver
- SecurityTokenResolver
當這個方法傳回時,會包含 SecurityTokenResolver。 這個參數會以未初始化的狀態傳遞。
傳回
安全性權杖驗證器
例外狀況
tokenRequirement
為 null
。
無法為傳入的tokenRequirement
建立安全性權杖驗證器。
範例
下列程式碼是說明如何覆寫這個方法的範例。
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
備註
outOfBand
方法可以選擇性地傳回權杖解析程式,這是 WCF 安全性處理器用來解析處理安全性時不在 SOAP 訊息中的權杖。 此方法傳回的 SecurityTokenAuthenticator 會驗證權杖,並擷取宣告。 每個衍生自 SecurityTokenAuthenticator 的類別都各有一個為其建立的 ServiceModelSecurityTokenRequirement。