SecurityTokenService 클래스

정의

STS(보안 토큰 서비스)의 메서드와 속성을 정의하는 추상 기본 클래스입니다.

public ref class SecurityTokenService abstract
public abstract class SecurityTokenService
type SecurityTokenService = class
Public MustInherit Class SecurityTokenService
상속
SecurityTokenService

예제

에 사용 되는 코드 예제는 SecurityTokenService 항목에서 수행 되는 Custom Token 샘플. 이 샘플에서는 간단한 웹 토큰 (SWT)의 처리를 사용 하도록 설정 하는 사용자 지정 클래스를 제공 하 고 SWT 토큰 서비스를 제공할 수 있는 패시브 STS 구현의 포함 되어 있습니다. 액티브 STS를 구현 하는 방법의 예 참조는 Federation Metadata 샘플입니다. 이러한 샘플 및 다른 샘플을 제공 하는 방법에 대 한 WIF에 대 한 다운로드 위치에 대 한, 참조 WIF 코드 샘플 인덱스합니다. 다음 코드에서는 사용 하 여 패시브 STS 구현의 SecurityTokenService 클래스입니다.

using System;
using System.IdentityModel;
using System.IdentityModel.Configuration;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;
using System.Security.Claims;
using System.Security.Cryptography.X509Certificates;

namespace PassiveSTS
{
    /// <summary>
    /// Overrides the SecurityTokenService class to provide
    /// the relying party related information, such as encryption credentials to encrypt the issued
    /// token, signing credentials to sign the issued token, claims that the STS wants to issue for a 
    /// certain token request, as well as the claim types that this STS is capable
    /// of issuing.
    /// </summary>
    public class CustomSecurityTokenService : SecurityTokenService
    {
        // Certificate Constants
        private const string SIGNING_CERTIFICATE_NAME = "CN=localhost";
        private const string ENCRYPTING_CERTIFICATE_NAME = "CN=localhost";

        private SigningCredentials _signingCreds;
        private EncryptingCredentials _encryptingCreds;
        // Used for validating applies to address, set to URI used in RP app of application, could also have been done via config
        private string _addressExpected = "http://localhost:19851/";
        public CustomSecurityTokenService(SecurityTokenServiceConfiguration configuration)
            : base(configuration)
        {
            // Setup the certificate our STS is going to use to sign the issued tokens
            _signingCreds = new X509SigningCredentials(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SIGNING_CERTIFICATE_NAME));

            // Note: In this sample app only a si   ngle RP identity is shown, which is localhost, and the certificate of that RP is 
            // populated as _encryptingCreds
            // If you have multiple RPs for the STS you would select the certificate that is specific to 
            // the RP that requests the token and then use that for _encryptingCreds
            _encryptingCreds = new X509EncryptingCredentials(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, ENCRYPTING_CERTIFICATE_NAME));
        }

        /// <summary>
        /// This method returns the configuration for the token issuance request. The configuration
        /// is represented by the Scope class. In our case, we are only capable of issuing a token to a
        /// single RP identity represented by the _encryptingCreds field.
        /// </summary>
        /// <param name="principal">The caller's principal</param>
        /// <param name="request">The incoming RST</param>
        /// <returns></returns>
        protected override Scope GetScope(ClaimsPrincipal principal, RequestSecurityToken request)
        {
            // Validate the AppliesTo address
            ValidateAppliesTo( request.AppliesTo );

            // Create the scope using the request AppliesTo address and the RP identity
            Scope scope = new Scope( request.AppliesTo.Uri.AbsoluteUri, _signingCreds );

            if (Uri.IsWellFormedUriString(request.ReplyTo, UriKind.Absolute))
            {
                if (request.AppliesTo.Uri.Host != new Uri(request.ReplyTo).Host)
                    scope.ReplyToAddress = request.AppliesTo.Uri.AbsoluteUri;
                else
                    scope.ReplyToAddress = request.ReplyTo;
            }
            else
            {
                Uri resultUri = null;
                if (Uri.TryCreate(request.AppliesTo.Uri, request.ReplyTo, out resultUri))
                    scope.ReplyToAddress = resultUri.AbsoluteUri;
                else
                    scope.ReplyToAddress = request.AppliesTo.Uri.ToString() ;
            }

            // Note: In this sample app only a single RP identity is shown, which is localhost, and the certificate of that RP is 
            // populated as _encryptingCreds
            // If you have multiple RPs for the STS you would select the certificate that is specific to 
            // the RP that requests the token and then use that for _encryptingCreds
            scope.EncryptingCredentials = _encryptingCreds;

            return scope;
        }
        /// <summary>
        /// This method returns the content of the issued token. The content is represented as a set of
        /// IClaimIdentity intances, each instance corresponds to a single issued token. Currently, the Windows Identity Foundation only
        /// supports a single token issuance, so the returned collection must always contain only a single instance.
        /// </summary>
        /// <param name="scope">The scope that was previously returned by GetScope method</param>
        /// <param name="principal">The caller's principal</param>
        /// <param name="request">The incoming RST, we don't use this in our implementation</param>
        /// <returns></returns>
        protected override ClaimsIdentity GetOutputClaimsIdentity( ClaimsPrincipal principal, RequestSecurityToken request, Scope scope )
        {
            //
            // Return a default claim set which contains a custom decision claim
            // Here you can actually examine the user by looking at the IClaimsPrincipal and 
            // return the right decision based on that. 
            //
            ClaimsIdentity outgoingIdentity = new ClaimsIdentity();
            outgoingIdentity.AddClaims(principal.Claims);

            return outgoingIdentity;
        }
        /// <summary>
        /// Validates the appliesTo and throws an exception if the appliesTo is null or appliesTo contains some unexpected address.
        /// </summary>
        /// <param name="appliesTo">The AppliesTo parameter in the request that came in (RST)</param>
        /// <returns></returns>
        void ValidateAppliesTo(EndpointReference appliesTo)
        {
            if (appliesTo == null)
            {
                throw new InvalidRequestException("The appliesTo is null.");
            }

            if (!appliesTo.Uri.Equals(new Uri(_addressExpected)))
            {
                throw new InvalidRequestException(String.Format("The relying party address is not valid. Expected value is {0}, the actual value is {1}.", _addressExpected, appliesTo.Uri.AbsoluteUri));
            }
        }

    }
}

다음 코드를 호출 하 여 Ws-federation 요청을 처리 하는 사용자 지정 패시브 STS를 호출 하는 방법을 보여 줍니다 합니다 FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(HttpRequest, ClaimsPrincipal, SecurityTokenService, HttpResponse) 뒤의 코드에서 메서드를 default.aspx.cs 파일입니다.

using System;
using System.IdentityModel.Services;
using System.Security.Claims;

namespace PassiveSTS
{
    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// We perform the WS-Federation Passive Protocol processing in this method. 
        /// </summary>
        protected void Page_PreRender( object sender, EventArgs e ) 
        {
            FederatedPassiveSecurityTokenServiceOperations.ProcessRequest( Request, User as ClaimsPrincipal, CustomSecurityTokenServiceConfiguration.Current.CreateSecurityTokenService(), Response );
        }
    }
}

설명

파생 되어야 하는 STS를 만들려면를 SecurityTokenService 클래스입니다. 사용자 지정 클래스에서를 최소한 재정의 해야 합니다 GetScopeGetOutputClaimsIdentity 메서드. 이러한 재정의 사용 하 여 기본 구현의 클래스에 정의 된 다른 모든 메서드를 사용 하 여 만든 STS는 토큰 요청 (RST) 보안에 대 한 응답에서 보안 토큰을 발급 수 있습니다. 즉, Ws-trust 사양에 정의 된 Issue 바인딩에 구현 됩니다. 이 바인딩은에서 구현 되는 Issue 메서드. Default case에서 구현 되는 다른 Ws-trust 바인딩이 (갱신, 취소 및 유효성 검사) 및 이러한 바인딩 중 하나에 해당 하는 RST 발견 되 면 호출자에 게 적절 한 오류가 반환 됩니다. 물론 적절 한 메서드를 재정의할 수 있습니다 (Renew, Cancel, 및 Validate) STS의 이러한 바인딩을 구현 합니다.

중요

신중 하 게 계획 하 고 이러한 서비스를 노출 하는의 본질적인 잠재적 보안 위험을 완화 하기 위해 상당한 리소스를 수반 프로덕션이 준비 된 STS를 구현 합니다. Windows Identity Foundation (WIF)를 사용 하 여 대부분의 개발자는 id 관리를 STS로 아웃소싱하는 애플리케이션 개발 되지 않고 자체 STS를 개발 합니다. WIF는 개발자가 개발 환경에서 솔루션을 테스트할 수 있도록 Id 및 액세스 도구 Visual Studio 2012 용 Visual Studio 확장을 제공 합니다. 이 도구에는 STS LocalSTS는 개발 중인 애플리케이션에 특정 클레임을 제공 하도록 구성할 수 있습니다. ID 및 액세스 도구에 대한 자세한 내용은 Visual Studio 2012용 ID 및 액세스 도구를 참조하세요. 일부 시나리오에서는 LocalSTS 적절 하 게 애플리케이션을 테스트 하는 데 필요한 기능을 제공 하지 않을 수 있습니다; 예를 들어 포함 된 경우 애플리케이션에서 사용 하기 위해 사용자 지정 토큰 처리기를 개발 합니다. 이러한 경우에서 파생할 수 있습니다 SecurityTokenService 개발 환경에서 배포할 수 있는 하 고 애플리케이션에서 이러한 기능을 테스트 하려면 사용할 수 있는 같은 하나 이상의 간단한 Sts를 만들려고 합니다. 이 섹션의 나머지 부분에서 노출 하는 방법에 중점을 둡니다는 SecurityTokenService 간단한 STS를 구현 하 고 토큰 발급 파이프라인을 확장할 수 있도록 하는 클래스입니다.

다음은 테스트 또는 개발 환경에서 사용 하기 위해 개발자에 게 가장 중요 방법의 간략 한 개요를 제공합니다.

  • GetScope 메서드 이 메서드는 반환 된 Scope RP에 대 한 정보를 포함 하는 개체입니다. 이 개체 토큰 발급 파이프라인의 나머지 부분에서 사용 되 고 응답에서 사용 하는 서명 및 암호화 자격 증명에 대 한 정보도 뿐만 AppliesToReplyTo (필요한 경우) 주소입니다. 이 메서드를 재정의 해야 합니다.

  • GetOutputClaimsIdentity 메서드 이 메서드가 반환을 ClaimsIdentity RP로 반환에 대 한 클레임을 포함 하는 개체입니다. 이 메서드를 재정의 해야 합니다.

  • Issue 메서드 이 메서드는 들어오는 보안 토큰 요청 (RST)을 처리 하 고 RP를 사용 하 여 인증을 사용할 수 있는 토큰을 포함 하는 호출자에 게 응답 (RSTR)을 반환 하는 토큰 요청 파이프라인을 구현 합니다. 에 정의 된 다른 메서드 중 대부분은 SecurityTokenService 클래스는이 메서드에서 호출 됩니다 포함 하 여는 GetScopeGetOutputClaimsIdentity 메서드. 이 메서드를 재정의할 필요는 없지만 구현 토큰 요청 파이프라인의 이해에 도움이 될 수 있습니다.

STS를 통해 구성 되는 SecurityTokenServiceConfiguration 클래스입니다.

구현자 참고

모두를 재정의 해야 합니다 GetScope(ClaimsPrincipal, RequestSecurityToken) 하며 GetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope) 메서드.

생성자

SecurityTokenService(SecurityTokenServiceConfiguration)

지정된 구성 설정을 사용하여 SecurityTokenService 클래스를 초기화하기 위해 파생된 클래스에서 호출됩니다.

속성

Principal

현재 인스턴스와 연결된 보안 주체를 가져오거나 설정합니다.

Request

현재 인스턴스와 연결된 RST(보안 토큰 요청)을 가져오거나 설정합니다.

Scope

현재 인스턴스와 연결된 범위를 가져오거나 설정합니다.

SecurityTokenDescriptor

현재 인스턴스와 연결된 SecurityTokenDescriptor를 가져오거나 설정합니다.

SecurityTokenServiceConfiguration

소유자 구성 인스턴스를 가져옵니다.

메서드

BeginCancel(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Cancel 요청을 시작합니다.

BeginGetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 GetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope) 메서드에 대한 비동기 호출을 시작합니다.

BeginGetScope(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 GetScope(ClaimsPrincipal, RequestSecurityToken) 메서드에 대한 비동기 호출을 시작합니다.

BeginIssue(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Issue 요청을 시작합니다.

BeginRenew(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Renew 요청을 시작합니다.

BeginValidate(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Validate 요청을 시작합니다.

Cancel(ClaimsPrincipal, RequestSecurityToken)

파생 클래스에서 재정의되는 경우 WS-Trust Cancel 요청을 처리합니다.

CreateSecurityTokenDescriptor(RequestSecurityToken, Scope)

SecurityTokenDescriptor의 인스턴스를 만듭니다.

EndCancel(IAsyncResult)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Cancel 요청을 완료합니다.

EndGetOutputClaimsIdentity(IAsyncResult)

파생 클래스에서 재정의되는 경우 BeginGetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope, AsyncCallback, Object) 메서드에 대한 비동기 호출을 완료합니다.

EndGetScope(IAsyncResult)

파생 클래스에서 재정의되는 경우 BeginGetScope(ClaimsPrincipal, RequestSecurityToken, AsyncCallback, Object) 메서드에 대한 비동기 호출을 완료합니다.

EndIssue(IAsyncResult)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Issue 요청을 완료합니다.

EndRenew(IAsyncResult)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Renew 요청을 완료합니다.

EndValidate(IAsyncResult)

파생 클래스에서 재정의되는 경우 비동기 WS-Trust Validate 요청을 완료합니다.

Equals(Object)

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

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

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

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

STS(보안 토큰 서비스)의 이름을 가져옵니다.

GetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope)

파생된 클래스에서 재정의된 경우 이 메서드는 발급된 토큰에 포함될 출력 주제 컬렉션을 반환합니다.

GetProofToken(RequestSecurityToken, Scope)

응답(RSTR)에 포함될 수 있는 증명 토큰을 가져옵니다.

GetRequestorProofEncryptingCredentials(RequestSecurityToken)

요청자의 증명 암호화 자격 증명을 가져옵니다.

GetResponse(RequestSecurityToken, SecurityTokenDescriptor)

지정된 요청(RST)과 보안 토큰 설명자를 사용하여 발급된 토큰이 들어 있는 응답(RSTR)을 만듭니다.

GetScope(ClaimsPrincipal, RequestSecurityToken)

지정된 요청(RST)과 연결된 RP(신뢰 당사자)에 대한 정보를 포함하는 Scope 개체를 가져옵니다. SecurityTokenService 클래스의 구현에서 이 메서드를 재정의해야 합니다.

GetSecurityTokenHandler(String)

지정된 형식의 보안 토큰을 발급하는 적절한 보안 토큰 처리기를 가져옵니다.

GetTokenLifetime(Lifetime)

발행된 토큰의 수명을 가져옵니다.

GetType()

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

(다음에서 상속됨 Object)
Issue(ClaimsPrincipal, RequestSecurityToken)

보안 토큰을 발급합니다.

MemberwiseClone()

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

(다음에서 상속됨 Object)
Renew(ClaimsPrincipal, RequestSecurityToken)

파생 클래스에서 재정의되는 경우 WS-Trust Renew 요청을 처리합니다.

ToString()

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

(다음에서 상속됨 Object)
Validate(ClaimsPrincipal, RequestSecurityToken)

파생 클래스에서 재정의되는 경우 WS-Trust Validate 요청을 처리합니다.

ValidateRequest(RequestSecurityToken)

이 인스턴스에 의해 캡슐화되는 보안 토큰 요청(RST)의 유효성을 검사합니다.

적용 대상

추가 정보