SecurityTokenProvider Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Olyan biztonsági jogkivonat-szolgáltatót jelöl, amely egy SOAP-üzenet feladójának biztonsági jogkivonatait kezeli.
public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
- Öröklődés
-
SecurityTokenProvider
- Származtatott
Példák
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
Megjegyzések
Akkor használja az SecurityTokenProvider osztályt, ha egyéni biztonsági jogkivonatokra van szükség. A biztonsági jogkivonat-szolgáltató feladata egy biztonsági jogkivonat lekérése, amikor egy ügyfél SOAP-üzenetet küld, és egy biztonsági jogkivonatot használ az ügyfél hitelesítésére vagy a SOAP-üzenet védelmére. A metódust GetToken egy biztonsági jogkivonat lekérésére hívjuk meg. A biztonsági jogkivonat-szolgáltató meghívható a biztonság megszakítására és megújítására is a metódusok és CancelToken módszerek RenewToken használatával.
Az osztályból SecurityTokenManager származó osztályok implementálják a CreateSecurityTokenProvider metódust annak meghatározásához, hogy melyik biztonsági jogkivonat-szolgáltatóra van szükség egy adott biztonsági jogkivonathoz.
Az ClientCredentialsSecurityTokenManager és ServiceCredentialsSecurityTokenManager az osztályok biztosítják a beépített biztonsági jogkivonat-típusok alapértelmezett implementációit. Egyéni biztonsági jogkivonat-forgatókönyvek esetén az osztályt az SecurityTokenManageregyik , ClientCredentialsSecurityTokenManagervagy ServiceCredentialsSecurityTokenManager osztályból kell származtatnia, és meg kell adnia a biztonsági jogkivonat-szolgáltató, a biztonsági jogkivonat-hitelesítő és a biztonsági jogkivonat szerializálójának az egyéni biztonsági jogkivonathoz való létrehozásához szükséges funkciókat. Az egyéni jogkivonatok létrehozásával kapcsolatos további információkért lásd: Egyéni jogkivonat létrehozása.
Konstruktorok
| Name | Description |
|---|---|
| SecurityTokenProvider() |
Inicializálja a SecurityTokenProvider osztály új példányát. |
Tulajdonságok
| Name | Description |
|---|---|
| SupportsTokenCancellation |
Olyan értéket kap, amely jelzi, hogy a biztonsági jogkivonat visszavonható-e. |
| SupportsTokenRenewal |
Olyan értéket kap, amely jelzi, hogy a biztonsági jogkivonat megújítható-e. |
Metódusok
| Name | Description |
|---|---|
| BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object) |
Elindít egy aszinkron műveletet egy biztonsági jogkivonat megszakításához. |
| BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Elindít egy aszinkron műveletet egy biztonsági jogkivonat megszakításához. |
| BeginGetToken(TimeSpan, AsyncCallback, Object) |
Elindít egy aszinkron műveletet egy biztonsági jogkivonat lekéréséhez. |
| BeginGetTokenCore(TimeSpan, AsyncCallback, Object) |
Elindít egy aszinkron műveletet egy biztonsági jogkivonat lekéréséhez. |
| BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object) |
Elindít egy aszinkron műveletet, amely megújít egy biztonsági jogkivonatot. |
| BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object) |
Elindít egy aszinkron műveletet, amely megújít egy biztonsági jogkivonatot. |
| CancelToken(TimeSpan, SecurityToken) |
Megszakít egy biztonsági jogkivonatot. |
| CancelTokenAsync(TimeSpan, SecurityToken) |
Megszakít egy biztonsági jogkivonatot. |
| CancelTokenCore(TimeSpan, SecurityToken) |
Megszakít egy biztonsági jogkivonatot. |
| CancelTokenCoreAsync(TimeSpan, SecurityToken) |
Megszakít egy biztonsági jogkivonatot. |
| EndCancelToken(IAsyncResult) |
Befejez egy aszinkron műveletet egy biztonsági jogkivonat megszakításához. |
| EndCancelTokenCore(IAsyncResult) |
Befejez egy aszinkron műveletet egy biztonsági jogkivonat megszakításához. |
| EndGetToken(IAsyncResult) |
Befejez egy aszinkron műveletet egy biztonsági jogkivonat lekéréséhez. |
| EndGetTokenCore(IAsyncResult) |
Befejez egy aszinkron műveletet egy biztonsági jogkivonat lekéréséhez. |
| EndRenewToken(IAsyncResult) |
Befejez egy aszinkron műveletet egy biztonsági jogkivonat megújításához. |
| EndRenewTokenCore(IAsyncResult) |
Befejez egy aszinkron műveletet a biztonsági jogkivonat megújításához. |
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetToken(TimeSpan) |
Biztonsági jogkivonatot kap. |
| GetTokenAsync(TimeSpan) |
Biztonsági jogkivonatot kap. |
| GetTokenCore(TimeSpan) |
Biztonsági jogkivonatot kap. |
| GetTokenCoreAsync(TimeSpan) |
Biztonsági jogkivonatot kap. |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| RenewToken(TimeSpan, SecurityToken) |
Megújít egy biztonsági jogkivonatot. |
| RenewTokenAsync(TimeSpan, SecurityToken) |
Megújít egy biztonsági jogkivonatot. |
| RenewTokenCore(TimeSpan, SecurityToken) |
Megújít egy biztonsági jogkivonatot. |
| RenewTokenCoreAsync(TimeSpan, SecurityToken) |
Megújít egy biztonsági jogkivonatot. |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |