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。