SecurityTokenProvider Třída

Definice

Představuje zprostředkovatele tokenů zabezpečení, který zpracovává tokeny zabezpečení pro odesílatele zprávy PROTOKOLU SOAP.

public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
Dědičnost
SecurityTokenProvider
Odvozené

Příklady

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

Poznámky

SecurityTokenProvider Pokud se vyžadují vlastní tokeny zabezpečení, použijte třídu . Role zprostředkovatele tokenů zabezpečení je získání tokenu zabezpečení, když klient odešle zprávu SOAP a token zabezpečení se používá k ověření klienta nebo k ochraně zprávy SOAP. Konkrétně se GetToken volá metoda pro získání tokenu zabezpečení. Zprostředkovatel tokenů zabezpečení je také možné volat, aby se zrušilo a obnovilo zabezpečení pomocí CancelToken metod a RenewToken .

Třídy odvozené z SecurityTokenManager třídy implementují metodu CreateSecurityTokenProvider k určení, který zprostředkovatel tokenu zabezpečení je požadován pro daný token zabezpečení.

Třídy ClientCredentialsSecurityTokenManager a ServiceCredentialsSecurityTokenManager poskytují výchozí implementace pro předdefinované typy tokenů zabezpečení. V případě vlastních scénářů tokenů zabezpečení je nutné odvodit třídu z jedné z SecurityTokenManagertříd , ClientCredentialsSecurityTokenManagernebo ServiceCredentialsSecurityTokenManager a poskytnout funkce pro vytvoření zprostředkovatele tokenů zabezpečení, ověřovacího tokenu zabezpečení a serializátoru tokenů zabezpečení pro vlastní token zabezpečení. Další informace o vytvoření vlastního tokenu najdete v tématu Postupy: Vytvoření vlastního tokenu.

Konstruktory

SecurityTokenProvider()

Inicializuje novou instanci SecurityTokenProvider třídy.

Vlastnosti

SupportsTokenCancellation

Získá hodnotu, která označuje, zda token zabezpečení lze zrušit.

SupportsTokenRenewal

Získá hodnotu, která označuje, zda token zabezpečení je obnovitelný.

Metody

BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Zahájí asynchronní operaci, která zruší token zabezpečení.

BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Zahájí asynchronní operaci, která zruší token zabezpečení.

BeginGetToken(TimeSpan, AsyncCallback, Object)

Zahájí asynchronní operaci, která získá token zabezpečení.

BeginGetTokenCore(TimeSpan, AsyncCallback, Object)

Zahájí asynchronní operaci, která získá token zabezpečení.

BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Spustí asynchronní operaci, která obnoví token zabezpečení.

BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Spustí asynchronní operaci, která obnoví token zabezpečení.

CancelToken(TimeSpan, SecurityToken)

Zruší token zabezpečení.

CancelTokenAsync(TimeSpan, SecurityToken)

Zruší token zabezpečení.

CancelTokenCore(TimeSpan, SecurityToken)

Zruší token zabezpečení.

CancelTokenCoreAsync(TimeSpan, SecurityToken)

Zruší token zabezpečení.

EndCancelToken(IAsyncResult)

Dokončí asynchronní operaci, která zruší token zabezpečení.

EndCancelTokenCore(IAsyncResult)

Dokončí asynchronní operaci, která zruší token zabezpečení.

EndGetToken(IAsyncResult)

Dokončí asynchronní operaci a získá token zabezpečení.

EndGetTokenCore(IAsyncResult)

Dokončí asynchronní operaci a získá token zabezpečení.

EndRenewToken(IAsyncResult)

Dokončí asynchronní operaci obnovení tokenu zabezpečení.

EndRenewTokenCore(IAsyncResult)

Dokončí asynchronní operaci obnovení tokenu zabezpečení.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetToken(TimeSpan)

Získá token zabezpečení.

GetTokenAsync(TimeSpan)

Získá token zabezpečení.

GetTokenCore(TimeSpan)

Získá token zabezpečení.

GetTokenCoreAsync(TimeSpan)

Získá token zabezpečení.

GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
RenewToken(TimeSpan, SecurityToken)

Obnoví token zabezpečení.

RenewTokenAsync(TimeSpan, SecurityToken)

Obnoví token zabezpečení.

RenewTokenCore(TimeSpan, SecurityToken)

Obnoví token zabezpečení.

RenewTokenCoreAsync(TimeSpan, SecurityToken)

Obnoví token zabezpečení.

ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také