SecurityTokenProvider Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Představuje zprostředkovatele tokenu zabezpečení, který zpracovává tokeny zabezpečení pro odesílatele zprávy 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 Třídu použijte v případě, že jsou vyžadovány vlastní tokeny zabezpečení. Role zprostředkovatele tokenu zabezpečení je získat token zabezpečení při odeslání zprávy SOAP klientem 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 tokenu zabezpečení lze také volat, aby se zrušilo a obnovilo zabezpečení pomocí metod CancelToken a RenewToken metod.
Třídy odvozené z SecurityTokenManager třídy implementují metodu CreateSecurityTokenProvider k určení, který zprostředkovatel tokenu zabezpečení je vyžadován pro daný token zabezpečení.
ClientCredentialsSecurityTokenManager Třídy ServiceCredentialsSecurityTokenManager poskytují výchozí implementace pro předdefinované typy tokenů zabezpečení. Pro vlastní scénáře tokenů zabezpečení je nutné odvodit třídu z jedné z SecurityTokenManager, ClientCredentialsSecurityTokenManagernebo ServiceCredentialsSecurityTokenManager třídy a poskytnout funkce pro vytvoření zprostředkovatele tokenu zabezpečení, ověřovací token zabezpečení a serializátor tokenu 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
| Name | Description |
|---|---|
| SecurityTokenProvider() |
Inicializuje novou instanci SecurityTokenProvider třídy. |
Vlastnosti
| Name | Description |
|---|---|
| SupportsTokenCancellation |
Získá hodnotu, která označuje, zda lze token zabezpečení zrušit. |
| SupportsTokenRenewal |
Získá hodnotu, která označuje, zda je token zabezpečení obnovitelný. |
Metody
| Name | Description |
|---|---|
| BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object) |
Zahájí asynchronní operaci zrušení tokenu zabezpečení. |
| BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Zahájí asynchronní operaci zrušení tokenu 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) |
Zahájí asynchronní operaci, která obnoví token zabezpečení. |
| BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Zahájí 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 a zruší token zabezpečení. |
| EndCancelTokenCore(IAsyncResult) |
Dokončí asynchronní operaci a 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 pro obnovení tokenu zabezpečení. |
| EndRenewTokenCore(IAsyncResult) |
Dokončí asynchronní operaci pro obnovení tokenu zabezpečení. |
| Equals(Object) |
Určuje, zda je zadaný objekt roven aktuálnímu objektu. (Zděděno od Object) |
| GetHashCode() |
Slouží jako výchozí funkce hash. (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á Type aktuální instance. (Zděděno od Object) |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (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) |