Aracılığıyla paylaş


SecurityTokenService.GetScope(ClaimsPrincipal, RequestSecurityToken) Yöntem

Tanım

Belirtilen istekle (RST) ilişkili bağlı olan taraf (RP) hakkında bilgi içeren bir Scope nesnesi alır. Sınıfı uygulamanızda bu yöntemi geçersiz kılmanız SecurityTokenService gerekir.

protected:
 abstract System::IdentityModel::Scope ^ GetScope(System::Security::Claims::ClaimsPrincipal ^ principal, System::IdentityModel::Protocols::WSTrust::RequestSecurityToken ^ request);
protected abstract System.IdentityModel.Scope GetScope (System.Security.Claims.ClaimsPrincipal principal, System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request);
abstract member GetScope : System.Security.Claims.ClaimsPrincipal * System.IdentityModel.Protocols.WSTrust.RequestSecurityToken -> System.IdentityModel.Scope
Protected MustOverride Function GetScope (principal As ClaimsPrincipal, request As RequestSecurityToken) As Scope

Parametreler

principal
ClaimsPrincipal

ClaimsPrincipal İstekte bulunan istemciyi temsil eden bir.

request
RequestSecurityToken

RequestSecurityToken Gelen isteği (RST) temsil eden bir.

Döndürülenler

Scope İstekle ilişkili RP bilgilerini kapsülleyen bir.

Örnekler

Bu konuda kullanılan kod örneği örnekten Custom Token alınmıştır. Bu örnek, Basit Web Belirteçlerinin (SWT) işlenmesini sağlayan özel sınıflar sağlar ve SWT belirtecini sunabilen pasif sts uygulamasını içerir. Etkin bir STS'nin nasıl uygulanabileceğine ilişkin bir örnek için örneği görebilirsiniz Federation Metadata . Bu örnekler ve WIF için kullanılabilen diğer örnekler ve bunların nereden indirileceği hakkında bilgi için bkz. WIF Kod Örneği Dizini.

Aşağıdaki kod örneği yönteminin GetScope bir uygulamasını gösterir. Bu uygulama, RP'nin STS tarafından tanındığını doğrular, istekteki adresi doğrular ReplyTo ve özelliği buna göre ayarlar Scope.ReplyToAddress ve imzalama ve şifreleme kimlik bilgilerini dosyada sabit kodlanmış sertifikalara göre RP ile kullanılacak şekilde ayarlar.

// 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/";
/// <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>
/// 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));
    }
}

Açıklamalar

GetScope yöntemi, yönteminden sonra ValidateRequest belirteç verme işlem hattından çağrılır ve gelen istek için yapılandırılmış bir Scope nesne döndürmelidir. (Belirteç verme işlem hattı yönteminde Issue uygulanır.) nesnesi, Scope güvenlik belirteci isteği (RST) ile ilişkili RP hakkındaki bilgileri kapsüller. Bu, RP ile kullanılacak şifreleme ve imzalama kimlik bilgileri ve verilen belirteçlerin ve/veya yanıttaki simetrik anahtarların şifrelenip şifrelenmediği hakkındaki bilgileri içerir. yönteminde GetScope gerçekleştirilen bazı tipik görevler şunlardır:

  • Belirtecin hedeflendiği RP'nin tanınan bir RP olup olmadığını belirleyin. Bunun nasıl gerçekleştirilmesi, uygulamanıza bağlıdır. Hedeflenen RP bu STS için geçerli bir RP değilse yöntemi bir InvalidRequestExceptionoluşturmalıdır.

  • Yanıtta (RSTR) kullanılacak imzalama kimlik bilgilerini belirleyin ve özelliği buna göre ayarlayın SigningCredentials .

  • Yanıtın ve/veya dahil edilen simetrik anahtarların şifrelenip şifrelenmeyeceğini ve şifreleme için kullanılacak kimlik bilgilerini belirleyin. TokenEncryptionRequired, SymmetricKeyEncryptionRequiredve EncryptingCredentials özelliklerini buna göre ayarlayın.

    Önemli

    Varsayılan olarak, TokenEncryptionRequired ve SymmetricKeyEncryptionRequired özellikleri STS'nin güvenli olmayan belirteçler vermesini engelleyecek şekilde ayarlanır true . Bu özelliklerin üretim ortamında hiçbir zaman olarak ayarlanmamış false olması önerilir.

  • Yanıtın döndürüleceği adresi belirleyin. AppliesToAddress veya ReplyToAddress özelliğini buna göre ayarlayın.

Uygulayanlara Notlar

Sınıfı uygulamanızda bu yöntemi geçersiz kılmanız SecurityTokenService gerekir.

Şunlara uygulanır

Ayrıca bkz.