다음을 통해 공유


방법: WSFederationHttpBinding 만들기

WCF(Windows Communication Foundation)에서 WSFederationHttpBinding 클래스(<wsFederationHttpBinding> 구성)는 페더레이션된 서비스를 노출하는 메커니즘을 제공합니다. 즉, 보안 토큰 서비스에서 발급된 보안 토큰을 사용하여 클라이언트가 인증해야 하는 서비스입니다. 이 항목에서는 코드와 구성 둘 다에서 WSFederationHttpBinding을 설정하는 방법을 보여 줍니다. 바인딩을 만들고 나면 해당 바인딩을 사용하도록 엔드포인트를 설정할 수 있습니다.

기본 단계는 다음과 같이 간략하게 설명됩니다.

  1. 보안 모드를 선택합니다. WSFederationHttpBinding은 여러 홉을 통과하는 경우에도 메시지 수준에서 엔드투엔드 보안을 제공하는 Message와 클라이언트 및 서비스가 HTTPS를 통해 직접 연결할 수 있는 경우 성능을 향상시키는 TransportWithMessageCredential을 지원합니다.

    참고 항목

    WSFederationHttpBinding은 보안 모드로 None도 지원합니다. 이 모드는 보안되지 않으며 디버깅 목적을 위해서만 제공됩니다. 보안 모드가 None으로 설정된 WSFederationHttpBinding과 함께 서비스 엔드포인트를 배포한 경우 결과 클라이언트 바인딩(ServiceModel Metadata Utility Tool(Svcutil.exe) 생성됨)은 보안 모드가 NoneWSHttpBinding입니다.

    다른 시스템 제공 바인딩과 달리 WSFederationHttpBinding을 사용할 때는 클라이언트 자격 증명 형식을 선택할 필요가 없습니다. 이는 클라이언트 자격 증명 형식이 항상 발급된 토큰이기 때문입니다. WCF는 지정된 발급자로부터 토큰을 받아서 서비스에 제공하여 클라이언트를 인증합니다.

  2. 페더레이션 클라이언트에서는 IssuerAddress 속성을 보안 토큰 서비스의 URL로 설정합니다. IssuerBinding을 보안 토큰 서비스와 통신하는 데 사용할 바인딩으로 설정합니다.

  3. 선택 사항. IssuedTokenType 속성을 토큰 형식의 URI(Uniform Resource Identifier)로 설정합니다. 연합 서비스에서는 서비스에 필요한 토큰 형식을 지정합니다. 페더레이션 클라이언트에서는 클라이언트가 보안 토큰 서비스에서 요청하는 토큰 형식을 지정합니다.

    토큰 형식을 지정하지 않으면 클라이언트는 토큰 URI 없이 WS-Trust RST(요청 보안 토큰)를 생성하며 기본적으로 SAML(Security Assertions Markup Language) 1.1 토큰을 사용한 클라이언트 인증이 서비스에 필요합니다.

    SAML 1.1 토큰에 대한 URI는 http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1입니다.

  4. 선택 사항. 연합 서비스에서는 IssuerMetadataAddress 속성을 보안 토큰 서비스의 메타데이터 URL로 설정합니다. 서비스의 클라이언트는 서비스가 메타데이터를 게시하도록 구성된 경우 메타데이터 엔드포인트를 사용하여 적절한 바인딩/엔드포인트 쌍을 선택할 수 있습니다. 메타데이터 게시에 대한 자세한 내용은 메타데이터 게시를 참조하세요.

발급된 토큰에서 증명 키로 사용되는 키의 형식, 클라이언트와 서비스 간에 사용할 알고리즘 모음, 서비스 자격 증명을 협상할지 또는 명시적으로 지정할지 여부, 서비스에서 발급된 토큰에 포함되어 있다고 예상하는 특정 클레임, 클라이언트가 보안 토큰 서비스에 보내는 요청에 추가해야 하는 추가 XML 요소 등의 다른 속성을 설정할 수도 있습니다.

참고 항목

NegotiateServiceCredential 속성은 SecurityModeMessage로 설정된 경우에만 관련이 있습니다. SecurityModeTransportWithMessageCredential로 설정하면 NegotiateServiceCredential 속성은 무시됩니다.

코드에서 WSFederationHttpBinding을 구성하려면

  1. WSFederationHttpBinding 인스턴스를 만듭니다.

  2. 필요에 따라 Mode 속성을 WSFederationHttpSecurityMode 또는 Message로 설정합니다. Basic256 이외의 알고리즘 모음이 필요한 경우 AlgorithmSuite 속성을 SecurityAlgorithmSuite에서 가져온 값으로 설정합니다.

  3. NegotiateServiceCredential 속성을 적절하게 설정합니다.

  4. 필요에 따라 IssuedKeyType 속성을 SecurityKeyTypeSymmetricKey 또는 .AsymmetricKey로 설정합니다.

  5. IssuedTokenType 속성을 적절한 값으로 설정합니다. 값이 설정되지 않은 경우 WCF는 기본적으로 SAML 1.1 토큰을 나타내는 http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1로 설정됩니다.

  6. 로컬 발급자가 지정되지 않은 경우 클라이언트에서는 필수적 요소이고 서비스에서는 선택적 요소입니다. 보안 토큰 서비스의 주소 및 ID 정보를 포함하는 EndpointAddress를 만들고 EndpointAddress 인스턴스를 IssuerAddress 속성에 할당합니다.

  7. 로컬 발급자가 지정되지 않은 경우 클라이언트에서는 필수적 요소이고 서비스에서는 사용되지 않습니다. SecurityTokenService에 대한 Binding을 만들고 IssuerBinding 속성에 Binding 인스턴스를 할당합니다.

  8. 클라이언트에서는 사용되지 않고 서비스에서는 선택적 요소입니다. 보안 토큰 서비스의 메타데이터에 대한 EndpointAddress 인스턴스를 만들어 IssuerMetadataAddress 속성에 할당합니다.

  9. 클라이언트와 서비스 둘 다에서 선택적 요소입니다. 하나 이상의 ClaimTypeRequirement 인스턴스를 만들어 ClaimTypeRequirements 속성에서 반환된 컬렉션에 추가합니다.

  10. 클라이언트와 서비스 둘 다에서 선택적 요소입니다. 하나 이상의 XmlElement 인스턴스를 만들어 TokenRequestParameters 속성에서 반환된 컬렉션에 추가합니다.

구성에서 연합 엔드포인트를 만들려면

  1. 애플리케이션 구성 파일에서 <바인딩> 요소의 자식으로 <wsFederationHttpBinding>을 만듭니다.

  2. <wsFederationHttpBinding>의 자식으로 <바인딩> 요소를 만들고 name 특성을 적절한 값으로 설정합니다.

  3. <security> 요소를 <바인딩> 요소의 자식으로 만듭니다.

  4. 필요에 따라 mode 요소의 <security> 특성을 Message 또는 TransportWithMessageCredential의 값으로 설정합니다.

  5. <message> 요소를 <security> 요소의 자식으로 만듭니다.

  6. 선택 사항. algorithmSuite 요소의 <message> 특성을 적절한 값으로 설정합니다. 기본값은 Basic256입니다.

  7. 선택 사항. 비대칭 증명 키가 필요한 경우 issuedKeyType 요소의 <message> 특성을 AsymmetricKey로 설정합니다. 기본값은 SymmetricKey입니다.

  8. 선택 사항. issuedTokenType 요소의 <message> 특성을 설정합니다.

  9. 로컬 발급자가 지정되지 않은 경우 클라이언트에서는 필수적 요소이고 서비스에서는 선택적 요소입니다. <issuer> 요소를 <message> 요소의 자식으로 만듭니다.

  10. address 특성을 <issuer> 요소로 설정하고 보안 토큰 서비스에서 토큰 요청을 수락하는 주소를 지정합니다.

  11. 선택 사항. <identity> 자식 요소를 추가하고 보안 토큰 서비스의 ID를 지정합니다.

  12. 자세한 내용은 서비스 Id 및 인증합니다.

  13. 로컬 발급자가 지정되지 않은 경우 클라이언트에서는 필수적 요소이고 서비스에서는 사용되지 않습니다. 보안 토큰 서비스와 통신하는 데 사용할 수 있는 바인딩 섹션에서 <바인딩> 요소를 만듭니다. 바인딩을 만드는 방법에 대한 자세한 내용은 방법: 구성에서 서비스 바인딩 지정을 참조하세요.

  14. binding 요소의 bindingConfiguration<issuer> 특성을 설정하여 이전 단계에서 만든 바인딩을 지정합니다.

  15. 클라이언트에서는 사용되지 않고 서비스에서는 선택적 요소입니다. <issuerMetadata> 요소를 <message> 요소의 자식으로 만듭니다. 그런 다음 address 요소의 <issuerMetadata> 특성에서 보안 토큰 서비스가 해당 메타데이터를 게시할 주소를 지정합니다. 선택적으로 <identity> 자식 요소를 추가하고 보안 토큰 서비스의 ID를 지정합니다.

  16. 클라이언트와 서비스 둘 다에서 선택적 요소입니다. <claimTypeRequirements> 요소를 <message> 요소의 자식으로 추가합니다. <추가> 요소를 <claimTypeRequirements> 요소에 추가하고 클레임 형식을 claimType 특성으로 지정하여 서비스에서 사용할 필수 및 선택적 클레임을 지정합니다. isOptional 특성을 설정하여 지정된 클레임이 필수 또는 선택적 요소인지 지정합니다.

예시

다음 코드 샘플에서는 명령적으로 WSFederationHttpBinding을 설정하는 코드를 보여 줍니다.

// This method creates a WSFederationHttpBinding.
public static WSFederationHttpBinding
    CreateWSFederationHttpBinding(bool isClient)
{
  // Create an instance of the WSFederationHttpBinding.
  WSFederationHttpBinding b = new WSFederationHttpBinding();

  // Set the security mode to Message.
  b.Security.Mode = WSFederationHttpSecurityMode.Message;

  // Set the Algorithm Suite to Basic256Rsa15.
  b.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256Rsa15;

  // Set NegotiateServiceCredential to true.
  b.Security.Message.NegotiateServiceCredential = true;

  // Set IssuedKeyType to Symmetric.
  b.Security.Message.IssuedKeyType = SecurityKeyType.SymmetricKey;

  // Set IssuedTokenType to SAML 1.1
  b.Security.Message.IssuedTokenType =
      "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#samlv1.1";
    
  // Extract the STS certificate from the certificate store.
  X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
  store.Open(OpenFlags.ReadOnly);
  X509Certificate2Collection certs = store.Certificates.Find(
      X509FindType.FindByThumbprint, "0000000000000000000000000000000000000000", false);
  store.Close();

  // Create an EndpointIdentity from the STS certificate.
  EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity ( certs[0] );

  // Set the IssuerAddress using the address of the STS and the previously created
  // EndpointIdentity.
  b.Security.Message.IssuerAddress =
      new EndpointAddress(new Uri("http://localhost:8000/sts/x509"), identity);

  // Set the IssuerBinding to a WSHttpBinding loaded from configuration.
  // The IssuerBinding is only used on federated clients.
  if (isClient)
  {
      b.Security.Message.IssuerBinding = new WSHttpBinding("Issuer");
  }

  // Set the IssuerMetadataAddress using the metadata address of the STS and the
  // previously created EndpointIdentity. The IssuerMetadataAddress is only used
  // on federated services.
  else
  {
      b.Security.Message.IssuerMetadataAddress =
          new EndpointAddress(new Uri("http://localhost:8001/sts/mex"), identity);
  }
  // Create a ClaimTypeRequirement.
  ClaimTypeRequirement ctr = new ClaimTypeRequirement
      ("http://example.org/claim/c1", false);

  // Add the ClaimTypeRequirement to ClaimTypeRequirements
  b.Security.Message.ClaimTypeRequirements.Add(ctr);

  // Return the created binding
  return b;
}
' This method creates a WSFederationHttpBinding.
Public Shared Function CreateWSFederationHttpBinding(ByVal isClient As Boolean) As WSFederationHttpBinding
    ' Create an instance of the WSFederationHttpBinding.
    Dim b As New WSFederationHttpBinding()
    With b.Security
        ' Set the security mode to Message.
        .Mode = WSFederationHttpSecurityMode.Message

        With .Message
            ' Set the Algorithm Suite to Basic256Rsa15.
            .AlgorithmSuite = SecurityAlgorithmSuite.Basic256Rsa15

            ' Set NegotiateServiceCredential to true.
            .NegotiateServiceCredential = True

            ' Set IssuedKeyType to Symmetric.
            .IssuedKeyType = SecurityKeyType.SymmetricKey

            ' Set IssuedTokenType to SAML 1.1
            .IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#samlv1.1"
        End With
    End With

    ' Extract the STS certificate from the certificate store.
    Dim store As New X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser)
    store.Open(OpenFlags.ReadOnly)
    Dim certs = store.Certificates.Find(X509FindType.FindByThumbprint, _
                                        "0000000000000000000000000000000000000000", _
                                        False)
    store.Close()

    ' Create an EndpointIdentity from the STS certificate.
    Dim identity = EndpointIdentity.CreateX509CertificateIdentity(certs(0))

    ' Set the IssuerAddress using the address of the STS and the previously created 
    ' EndpointIdentity.
    With b.Security.Message
        .IssuerAddress = New EndpointAddress(New Uri("http://localhost:8000/sts/x509"), _
                                                                           identity)

        ' Set the IssuerBinding to a WSHttpBinding loaded from configuration. 
        ' The IssuerBinding is only used on federated clients.
        If isClient Then
            .IssuerBinding = New WSHttpBinding("Issuer")

            ' Set the IssuerMetadataAddress using the metadata address of the STS and the
            ' previously created EndpointIdentity. The IssuerMetadataAddress is only used 
            ' on federated services.
        Else
            .IssuerMetadataAddress = New EndpointAddress(New Uri("http://localhost:8001/sts/mex"), _
                                                                           identity)
        End If
        ' Create a ClaimTypeRequirement.
        Dim ctr As New ClaimTypeRequirement("http://example.org/claim/c1", _
                                            False)

        ' Add the ClaimTypeRequirement to ClaimTypeRequirements
        .ClaimTypeRequirements.Add(ctr)
    End With

    ' Return the created binding
    Return b
End Function

참고 항목