SecurityTokenProvider 클래스

정의

SOAP 메시지를 보낸 사람의 보안 토큰을 처리하는 보안 토큰 공급자를 나타냅니다.

public ref class SecurityTokenProvider abstract
public abstract class SecurityTokenProvider
type SecurityTokenProvider = class
Public MustInherit Class SecurityTokenProvider
상속
SecurityTokenProvider
파생

예제

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

설명

사용자 지정 보안 토큰이 SecurityTokenProvider 필요한 경우 클래스를 사용합니다. 보안 토큰 공급자의 역할은 클라이언트가 SOAP 메시지를 보내고 보안 토큰을 사용하여 클라이언트를 인증하거나 SOAP 메시지를 보호하는 경우 보안 토큰을 가져오는 것입니다. 특히 보안 토큰을 GetToken 가져오기 위해 메서드가 호출됩니다. 보안 토큰 공급자를 호출하여 보안 RenewToken 및 메서드를 사용하여 CancelToken 보안을 취소하고 갱신할 수도 있습니다.

클래스에서 SecurityTokenManager 파생되는 클래스는 지정된 보안 토큰에 필요한 보안 토큰 공급자를 결정하는 메서드를 구현 CreateSecurityTokenProvider 합니다.

ServiceCredentialsSecurityTokenManager 클래스는 ClientCredentialsSecurityTokenManager 기본 제공 보안 토큰 형식에 대한 기본 구현을 제공합니다. 사용자 지정 보안 토큰 시나리오의 경우 , 또는 ServiceCredentialsSecurityTokenManager 클래스 중 SecurityTokenManagerClientCredentialsSecurityTokenManager하나에서 클래스를 파생하고 사용자 지정 보안 토큰에 대한 보안 토큰 공급자, 보안 토큰 인증자 및 보안 토큰 serializer를 만드는 기능을 제공해야 합니다. 사용자 지정 토큰을 만드는 방법에 대한 자세한 내용은 방법: 사용자 지정 토큰 만들기를 참조하세요.

생성자

SecurityTokenProvider()

SecurityTokenProvider 클래스의 새 인스턴스를 초기화합니다.

속성

SupportsTokenCancellation

보안 토큰을 취소할 수 있는지 여부를 나타내는 값을 가져옵니다.

SupportsTokenRenewal

보안 토큰을 갱신할 수 있는지 여부를 나타내는 값을 가져옵니다.

메서드

BeginCancelToken(TimeSpan, SecurityToken, AsyncCallback, Object)

보안 토큰을 취소하는 비동기 작업을 시작합니다.

BeginCancelTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

보안 토큰을 취소하는 비동기 작업을 시작합니다.

BeginGetToken(TimeSpan, AsyncCallback, Object)

보안 토큰을 가져오는 비동기 작업을 시작합니다.

BeginGetTokenCore(TimeSpan, AsyncCallback, Object)

보안 토큰을 가져오는 비동기 작업을 시작합니다.

BeginRenewToken(TimeSpan, SecurityToken, AsyncCallback, Object)

보안 토큰을 갱신하는 비동기 작업을 시작합니다.

BeginRenewTokenCore(TimeSpan, SecurityToken, AsyncCallback, Object)

보안 토큰을 갱신하는 비동기 작업을 시작합니다.

CancelToken(TimeSpan, SecurityToken)

보안 토큰을 취소합니다.

CancelTokenAsync(TimeSpan, SecurityToken)

보안 토큰을 취소합니다.

CancelTokenCore(TimeSpan, SecurityToken)

보안 토큰을 취소합니다.

CancelTokenCoreAsync(TimeSpan, SecurityToken)

보안 토큰을 취소합니다.

EndCancelToken(IAsyncResult)

보안 토큰을 취소하는 비동기 작업을 완료합니다.

EndCancelTokenCore(IAsyncResult)

보안 토큰을 취소하는 비동기 작업을 완료합니다.

EndGetToken(IAsyncResult)

보안 토큰을 가져오는 비동기 작업을 완료합니다.

EndGetTokenCore(IAsyncResult)

보안 토큰을 가져오는 비동기 작업을 완료합니다.

EndRenewToken(IAsyncResult)

보안 토큰을 갱신하는 비동기 작업을 완료합니다.

EndRenewTokenCore(IAsyncResult)

보안 토큰을 갱신하는 비동기 작업을 완료합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetToken(TimeSpan)

보안 토큰을 가져옵니다.

GetTokenAsync(TimeSpan)

보안 토큰을 가져옵니다.

GetTokenCore(TimeSpan)

보안 토큰을 가져옵니다.

GetTokenCoreAsync(TimeSpan)

보안 토큰을 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
RenewToken(TimeSpan, SecurityToken)

보안 토큰을 갱신합니다.

RenewTokenAsync(TimeSpan, SecurityToken)

보안 토큰을 갱신합니다.

RenewTokenCore(TimeSpan, SecurityToken)

보안 토큰을 갱신합니다.

RenewTokenCoreAsync(TimeSpan, SecurityToken)

보안 토큰을 갱신합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보