SecurityTokenProvider Klas

Definitie

Vertegenwoordigt een beveiligingstokenprovider die beveiligingstokens verwerkt voor een SOAP-berichtzender.

public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
Overname
SecurityTokenProvider
Afgeleid

Voorbeelden

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

Opmerkingen

Gebruik de SecurityTokenProvider klasse wanneer aangepaste beveiligingstokens vereist zijn. De rol van een beveiligingstokenprovider is het ophalen van een beveiligingstoken wanneer een SOAP-bericht wordt verzonden door een client en een beveiligingstoken wordt gebruikt om de client te verifiëren of om het SOAP-bericht te beveiligen. GetToken De methode wordt specifiek aangeroepen om een beveiligingstoken op te halen. De beveiligingstokenprovider kan ook worden aangeroepen om een beveiliging te annuleren en te vernieuwen met behulp van de CancelToken en RenewToken methoden.

Klassen die zijn afgeleid van de SecurityTokenManager klasse implementeren de CreateSecurityTokenProvider methode om te bepalen welke beveiligingstokenprovider is vereist voor een bepaald beveiligingstoken.

De ClientCredentialsSecurityTokenManager en ServiceCredentialsSecurityTokenManager klassen bieden de standaard implementaties voor ingebouwde typen beveiligingstokens. Voor aangepaste beveiligingstokenscenario's moet u een klasse afleiden uit een van de SecurityTokenManager, ClientCredentialsSecurityTokenManagerof ServiceCredentialsSecurityTokenManager klassen en de functionaliteit bieden om de beveiligingstokenprovider, de verificator voor beveiligingstokens en de serialisatiefunctie voor beveiligingstokens voor het aangepaste beveiligingstoken te maken. Zie Een aangepast token maken voor meer informatie over het maken van een aangepast token.

Constructors

Name Description
SecurityTokenProvider()

Initialiseert een nieuw exemplaar van de SecurityTokenProvider klasse.

Eigenschappen

Name Description
SupportsTokenCancellation

Hiermee wordt een waarde opgehaald die aangeeft of het beveiligingstoken kan worden geannuleerd.

SupportsTokenRenewal

Hiermee wordt een waarde opgehaald die aangeeft of het beveiligingstoken kan worden verlengd.

Methoden

Name Description
BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Hiermee wordt een asynchrone bewerking gestart om een beveiligingstoken te annuleren.

BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Hiermee wordt een asynchrone bewerking gestart om een beveiligingstoken te annuleren.

BeginGetToken(TimeSpan, AsyncCallback, Object)

Begint een asynchrone bewerking om een beveiligingstoken op te halen.

BeginGetTokenCore(TimeSpan, AsyncCallback, Object)

Begint een asynchrone bewerking om een beveiligingstoken op te halen.

BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object)

Hiermee wordt een asynchrone bewerking gestart waarmee een beveiligingstoken wordt vernieuwd.

BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

Hiermee wordt een asynchrone bewerking gestart waarmee een beveiligingstoken wordt vernieuwd.

CancelToken(TimeSpan, SecurityToken)

Hiermee annuleert u een beveiligingstoken.

CancelTokenCore(TimeSpan, SecurityToken)

Hiermee annuleert u een beveiligingstoken.

EndCancelToken(IAsyncResult)

Hiermee voltooit u een asynchrone bewerking om een beveiligingstoken te annuleren.

EndCancelTokenCore(IAsyncResult)

Hiermee voltooit u een asynchrone bewerking om een beveiligingstoken te annuleren.

EndGetToken(IAsyncResult)

Voltooit een asynchrone bewerking om een beveiligingstoken op te halen.

EndGetTokenCore(IAsyncResult)

Voltooit een asynchrone bewerking om een beveiligingstoken op te halen.

EndRenewToken(IAsyncResult)

Voltooit een asynchrone bewerking om een beveiligingstoken te vernieuwen.

EndRenewTokenCore(IAsyncResult)

Hiermee wordt een asynchrone bewerking voltooid om het beveiligingstoken te vernieuwen.

Equals(Object)

Bepaalt of het opgegeven object gelijk is aan het huidige object.

(Overgenomen van Object)
GetHashCode()

Fungeert als de standaardhashfunctie.

(Overgenomen van Object)
GetToken(TimeSpan)

Hiermee haalt u een beveiligingstoken op.

GetTokenCore(TimeSpan)

Hiermee haalt u een beveiligingstoken op.

GetType()

Hiermee haalt u de Type huidige instantie op.

(Overgenomen van Object)
MemberwiseClone()

Hiermee maakt u een ondiepe kopie van de huidige Object.

(Overgenomen van Object)
RenewToken(TimeSpan, SecurityToken)

Een beveiligingstoken wordt vernieuwd.

RenewTokenCore(TimeSpan, SecurityToken)

Een beveiligingstoken wordt vernieuwd.

ToString()

Retourneert een tekenreeks die het huidige object vertegenwoordigt.

(Overgenomen van Object)

Van toepassing op

Zie ook