SecurityTokenProvider Klasa

Definicja

Reprezentuje dostawcę tokenu zabezpieczającego, który obsługuje tokeny zabezpieczające dla nadawcy komunikatów PROTOKOŁU SOAP.

public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
Dziedziczenie
SecurityTokenProvider
Pochodne

Przykłady

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

Uwagi

Użyj klasy, SecurityTokenProvider gdy wymagane są niestandardowe tokeny zabezpieczające. Rolą dostawcy tokenu zabezpieczającego jest uzyskanie tokenu zabezpieczającego, gdy komunikat PROTOKOŁU SOAP jest wysyłany przez klienta, a token zabezpieczający jest używany do uwierzytelniania klienta lub ochrony komunikatu SOAP. W szczególności wywoływana GetToken jest metoda w celu uzyskania tokenu zabezpieczającego. Dostawca tokenu zabezpieczającego można również wywołać w celu anulowania i odnowienia zabezpieczeń przy użyciu CancelToken metod i RenewToken .

Klasy pochodzące z SecurityTokenManager klasy implementują metodę CreateSecurityTokenProvider w celu określenia, który dostawca tokenów zabezpieczających jest wymagany dla danego tokenu zabezpieczającego.

Klasy ClientCredentialsSecurityTokenManager i ServiceCredentialsSecurityTokenManager zapewniają domyślne implementacje wbudowanych typów tokenów zabezpieczających. W przypadku niestandardowych scenariuszy tokenu zabezpieczającego należy utworzyć klasę z jednej z SecurityTokenManagerklas , ClientCredentialsSecurityTokenManagerlub ServiceCredentialsSecurityTokenManager i zapewnić funkcjonalność tworzenia dostawcy tokenów zabezpieczających, wystawcy uwierzytelnienia tokenu zabezpieczającego i serializatora tokenów zabezpieczających dla niestandardowego tokenu zabezpieczającego. Aby uzyskać więcej informacji na temat tworzenia tokenu niestandardowego, zobacz Instrukcje: tworzenie tokenu niestandardowego.

Konstruktory

SecurityTokenProvider()

Inicjuje nowe wystąpienie klasy SecurityTokenProvider.

Właściwości

SupportsTokenCancellation

Pobiera wartość wskazującą, czy token zabezpieczający można anulować.

SupportsTokenRenewal

Pobiera wartość wskazującą, czy token zabezpieczający jest odnawialny.

Metody

BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną, aby anulować token zabezpieczający.

BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną, aby anulować token zabezpieczający.

BeginGetToken(TimeSpan, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną w celu uzyskania tokenu zabezpieczającego.

BeginGetTokenCore(TimeSpan, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną w celu uzyskania tokenu zabezpieczającego.

BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną, która odnawia token zabezpieczający.

BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Rozpoczyna operację asynchroniczną, która odnawia token zabezpieczający.

CancelToken(TimeSpan, SecurityToken)

Anuluje token zabezpieczający.

CancelTokenAsync(TimeSpan, SecurityToken)

Anuluje token zabezpieczający.

CancelTokenCore(TimeSpan, SecurityToken)

Anuluje token zabezpieczający.

CancelTokenCoreAsync(TimeSpan, SecurityToken)

Anuluje token zabezpieczający.

EndCancelToken(IAsyncResult)

Kończy operację asynchroniczną w celu anulowania tokenu zabezpieczającego.

EndCancelTokenCore(IAsyncResult)

Kończy operację asynchroniczną w celu anulowania tokenu zabezpieczającego.

EndGetToken(IAsyncResult)

Kończy operację asynchroniczną w celu uzyskania tokenu zabezpieczającego.

EndGetTokenCore(IAsyncResult)

Kończy operację asynchroniczną w celu uzyskania tokenu zabezpieczającego.

EndRenewToken(IAsyncResult)

Kończy operację asynchroniczną w celu odnowienia tokenu zabezpieczającego.

EndRenewTokenCore(IAsyncResult)

Kończy operację asynchroniczną w celu odnowienia tokenu zabezpieczającego.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetToken(TimeSpan)

Pobiera token zabezpieczający.

GetTokenAsync(TimeSpan)

Pobiera token zabezpieczający.

GetTokenCore(TimeSpan)

Pobiera token zabezpieczający.

GetTokenCoreAsync(TimeSpan)

Pobiera token zabezpieczający.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
RenewToken(TimeSpan, SecurityToken)

Odnawia token zabezpieczający.

RenewTokenAsync(TimeSpan, SecurityToken)

Odnawia token zabezpieczający.

RenewTokenCore(TimeSpan, SecurityToken)

Odnawia token zabezpieczający.

RenewTokenCoreAsync(TimeSpan, SecurityToken)

Odnawia token zabezpieczający.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też