SecurityTokenProvider Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
SOAP iletisi göndereni için güvenlik belirteçlerini işleyen bir güvenlik belirteci sağlayıcısını temsil eder.
public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
- Devralma
-
SecurityTokenProvider
- Türetilmiş
Örnekler
using System;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.IO;
using System.ServiceModel.Security;
using System.Xml;
namespace Microsoft.ServiceModel.Samples
{
/// <summary>
/// class that derives from SecurityTokenProvider and returns a SecurityToken representing a SAML assertion
/// </summary>
public class SamlSecurityTokenProvider : SecurityTokenProvider
{
/// <summary>
/// The SAML assertion that the SamlSecurityTokenProvider will return as a SecurityToken
/// </summary>
SamlAssertion assertion;
/// <summary>
/// The proof token associated with the SAML assertion
/// </summary>
SecurityToken proofToken;
/// <summary>
/// Constructor
/// </summary>
/// <param name="assertion">The SAML assertion that the SamlSecurityTokenProvider will return as a SecurityToken</param>
/// <param name="proofToken">The proof token associated with the SAML assertion</param>
public SamlSecurityTokenProvider(SamlAssertion assertion, SecurityToken proofToken )
{
this.assertion = assertion;
this.proofToken = proofToken;
}
/// <summary>
/// Creates the security token
/// </summary>
/// <param name="timeout">Maximum amount of time the method is supposed to take. Ignored in this implementation.</param>
/// <returns>A SecurityToken corresponding the SAML assertion and proof key specified at construction time</returns>
protected override SecurityToken GetTokenCore(TimeSpan timeout)
{
// Create a SamlSecurityToken from the provided assertion
SamlSecurityToken samlToken = new SamlSecurityToken(assertion);
// Create a SecurityTokenSerializer that will be used to serialize the SamlSecurityToken
WSSecurityTokenSerializer ser = new WSSecurityTokenSerializer();
// Create a memory stream to write the serialized token into
// Use an initial size of 64Kb
MemoryStream s = new MemoryStream(UInt16.MaxValue);
// Create an XmlWriter over the stream
XmlWriter xw = XmlWriter.Create(s);
// Write the SamlSecurityToken into the stream
ser.WriteToken(xw, samlToken);
// Seek back to the beginning of the stream
s.Seek(0, SeekOrigin.Begin);
// Load the serialized token into a DOM
XmlDocument dom = new XmlDocument();
dom.Load(s);
// Create a KeyIdentifierClause for the SamlSecurityToken
SamlAssertionKeyIdentifierClause samlKeyIdentifierClause = samlToken.CreateKeyIdentifierClause<SamlAssertionKeyIdentifierClause>();
// Return a GenericXmlToken from the XML for the SamlSecurityToken, the proof token, the valid from
// and valid until times from the assertion and the key identifier clause created above
return new GenericXmlSecurityToken(dom.DocumentElement, proofToken, assertion.Conditions.NotBefore, assertion.Conditions.NotOnOrAfter, samlKeyIdentifierClause, samlKeyIdentifierClause, null);
}
}
}
Imports System.IdentityModel.Selectors
Imports System.IdentityModel.Tokens
Imports System.IO
Imports System.ServiceModel.Security
Imports System.Xml
'/ <summary>
'/ class that derives from SecurityTokenProvider and returns a SecurityToken representing a SAML assertion
'/ </summary>
Public Class SamlSecurityTokenProvider
Inherits SecurityTokenProvider
'/ <summary>
'/ The SAML assertion that the SamlSecurityTokenProvider will return as a SecurityToken
'/ </summary>
Private assertion As SamlAssertion
'/ <summary>
'/ The proof token associated with the SAML assertion
'/ </summary>
Private proofToken As SecurityToken
'/ <summary>
'/ Constructor
'/ </summary>
'/ <param name="assertion">The SAML assertion that the SamlSecurityTokenProvider will return as a SecurityToken</param>
'/ <param name="proofToken">The proof token associated with the SAML assertion</param>
Public Sub New(ByVal assertion As SamlAssertion, ByVal proofToken As SecurityToken)
Me.assertion = assertion
Me.proofToken = proofToken
End Sub
'/ <summary>
'/ Creates the security token
'/ </summary>
'/ <param name="timeout">Maximum amount of time the method is supposed to take. Ignored in this implementation.</param>
'/ <returns>A SecurityToken corresponding the SAML assertion and proof key specified at construction time</returns>
Protected Overrides Function GetTokenCore(ByVal timeout As TimeSpan) As SecurityToken
' Create a SamlSecurityToken from the provided assertion
Dim samlToken As New SamlSecurityToken(assertion)
' Create a SecurityTokenSerializer that will be used to serialize the SamlSecurityToken
Dim ser As New WSSecurityTokenSerializer()
' Create a memory stream to write the serialized token into
' Use an initial size of 64Kb
Dim s As New MemoryStream(UInt16.MaxValue)
' Create an XmlWriter over the stream
Dim xw As XmlWriter = XmlWriter.Create(s)
' Write the SamlSecurityToken into the stream
ser.WriteToken(xw, samlToken)
' Seek back to the beginning of the stream
s.Seek(0, SeekOrigin.Begin)
' Load the serialized token into a DOM
Dim dom As New XmlDocument()
dom.Load(s)
' Create a KeyIdentifierClause for the SamlSecurityToken
Dim samlKeyIdentifierClause As SamlAssertionKeyIdentifierClause = samlToken.CreateKeyIdentifierClause(Of SamlAssertionKeyIdentifierClause)()
' Return a GenericXmlToken from the XML for the SamlSecurityToken, the proof token, the valid from
' and valid until times from the assertion and the key identifier clause created above
Return New GenericXmlSecurityToken(dom.DocumentElement, proofToken, assertion.Conditions.NotBefore, assertion.Conditions.NotOnOrAfter, samlKeyIdentifierClause, samlKeyIdentifierClause, Nothing)
End Function 'GetTokenCore
End Class
Açıklamalar
Özel güvenlik belirteçleri gerektiğinde sınıfını SecurityTokenProvider kullanın. Güvenlik belirteci sağlayıcısının rolü, istemci tarafından soap iletisi gönderildiğinde ve istemcinin kimliğini doğrulamak veya SOAP iletisini korumak için bir güvenlik belirteci kullanıldığında güvenlik belirteci almaktır. Özellikle, GetToken bir güvenlik belirteci almak için yöntemi çağrılır. Güvenlik belirteci sağlayıcısı, ve CancelToken yöntemlerini kullanarak bir güvenliği iptal etmek ve yenilemek RenewToken için de çağrılabilir.
sınıfından SecurityTokenManager türetilen sınıflar, belirli bir güvenlik belirteci için hangi güvenlik belirteci sağlayıcısının gerekli olduğunu belirlemek için yöntemini uygular CreateSecurityTokenProvider .
ClientCredentialsSecurityTokenManager ve ServiceCredentialsSecurityTokenManager sınıfları, yerleşik güvenlik belirteci türleri için varsayılan uygulamaları sağlar. Özel güvenlik belirteci senaryoları için , SecurityTokenManagerveya ClientCredentialsSecurityTokenManager sınıflarından ServiceCredentialsSecurityTokenManagerbirinden bir sınıf türetmelisiniz ve özel güvenlik belirteci için güvenlik belirteci sağlayıcısı, güvenlik belirteci doğrulayıcı ve güvenlik belirteci serileştiricisi oluşturma işlevselliğini sağlamanız gerekir. Özel belirteç oluşturma hakkında daha fazla bilgi için bkz . Nasıl yapılır: Özel Belirteç Oluşturma.
Oluşturucular
| Name | Description |
|---|---|
| SecurityTokenProvider() |
SecurityTokenProvider sınıfının yeni bir örneğini başlatır. |
Özellikler
| Name | Description |
|---|---|
| SupportsTokenCancellation |
Güvenlik belirtecinin iptal edilip edilemeyeceğini gösteren bir değer alır. |
| SupportsTokenRenewal |
Güvenlik belirtecinin yenilenebilir olup olmadığını gösteren bir değer alır. |
Yöntemler
| Name | Description |
|---|---|
| BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object) |
Bir güvenlik belirtecini iptal etmek için zaman uyumsuz bir işlem başlatır. |
| BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Bir güvenlik belirtecini iptal etmek için zaman uyumsuz bir işlem başlatır. |
| BeginGetToken(TimeSpan, AsyncCallback, Object) |
Güvenlik belirtecini almak için zaman uyumsuz bir işlem başlatır. |
| BeginGetTokenCore(TimeSpan, AsyncCallback, Object) |
Güvenlik belirtecini almak için zaman uyumsuz bir işlem başlatır. |
| BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object) |
Bir güvenlik belirtecini yenileyen zaman uyumsuz bir işlem başlatır. |
| BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Bir güvenlik belirtecini yenileyen zaman uyumsuz bir işlem başlatır. |
| CancelToken(TimeSpan, SecurityToken) |
Güvenlik belirtecini iptal eder. |
| CancelTokenAsync(TimeSpan, SecurityToken) |
Güvenlik belirtecini iptal eder. |
| CancelTokenCore(TimeSpan, SecurityToken) |
Güvenlik belirtecini iptal eder. |
| CancelTokenCoreAsync(TimeSpan, SecurityToken) |
Güvenlik belirtecini iptal eder. |
| EndCancelToken(IAsyncResult) |
Bir güvenlik belirtecini iptal etmek için zaman uyumsuz bir işlemi tamamlar. |
| EndCancelTokenCore(IAsyncResult) |
Bir güvenlik belirtecini iptal etmek için zaman uyumsuz bir işlemi tamamlar. |
| EndGetToken(IAsyncResult) |
Güvenlik belirteci almak için zaman uyumsuz bir işlemi tamamlar. |
| EndGetTokenCore(IAsyncResult) |
Güvenlik belirteci almak için zaman uyumsuz bir işlemi tamamlar. |
| EndRenewToken(IAsyncResult) |
Bir güvenlik belirtecini yenilemek için zaman uyumsuz bir işlemi tamamlar. |
| EndRenewTokenCore(IAsyncResult) |
Güvenlik belirtecini yenilemek için zaman uyumsuz bir işlemi tamamlar. |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetToken(TimeSpan) |
Bir güvenlik belirteci alır. |
| GetTokenAsync(TimeSpan) |
Bir güvenlik belirteci alır. |
| GetTokenCore(TimeSpan) |
Bir güvenlik belirteci alır. |
| GetTokenCoreAsync(TimeSpan) |
Bir güvenlik belirteci alır. |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| RenewToken(TimeSpan, SecurityToken) |
Bir güvenlik belirtecini yeniler. |
| RenewTokenAsync(TimeSpan, SecurityToken) |
Bir güvenlik belirtecini yeniler. |
| RenewTokenCore(TimeSpan, SecurityToken) |
Bir güvenlik belirtecini yeniler. |
| RenewTokenCoreAsync(TimeSpan, SecurityToken) |
Bir güvenlik belirtecini yeniler. |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |