다음을 통해 공유


방법: 동일한 형식의 여러 보안 토큰 사용

  • .NET Framework 3.0의 경우 클라이언트 메시지에 지정된 형식의 토큰을 하나만 포함할 수 있었지만, 이제 클라이언트 메시지에 특정 형식의 여러 토큰을 포함할 수 있습니다. 이 항목에서는 동일한 형식의 토큰을 클라이언트 메시지에 여러 개 포함하는 방법을 보여 줍니다.

  • 서비스는 이러한 방식으로 구성할 수 없습니다. 서비스는 지원하는 토큰을 하나만 포함할 수 있습니다.

동일한 형식의 보안 토큰을 여러 개 사용하려면

  1. 바인딩 요소로 채울 빈 바인딩 요소 컬렉션을 만듭니다.

    // Create an empty BindingElementCollection to populate, 
    // then create a custom binding from it.
    BindingElementCollection bec = new BindingElementCollection();
    
  2. CreateMutualCertificateBindingElement를 호출하여 SecurityBindingElement를 만듭니다.

    SecurityBindingElement sbe = SecurityBindingElement.CreateMutualCertificateBindingElement();
    
  3. SupportingTokenParameters 컬렉션을 만듭니다.

    SupportingTokenParameters supportParams = new SupportingTokenParameters();
    
  4. 컬렉션에 SAML 토큰을 추가합니다.

    // Two supporting SAML tokens are being added.
    supportParams.SignedEndorsing.Add(new IssuedSecurityTokenParameters("samlTokenType", issuerEndpointAddress1, issuerBinding1));
    supportParams.SignedEndorsing.Add(new IssuedSecurityTokenParameters("samlTokenType", issuerEndpointAddress2, issuerBinding2));
    
  5. SecurityBindingElement에 컬렉션을 추가합니다.

    ((SymmetricSecurityBindingElement)sbe).OperationSupportingTokenParameters.Add("*", supportParams);
    
  6. 바인딩 요소 컬렉션에 바인딩 요소를 추가합니다.

    bec.Add(sbe);
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    
  7. 바인딩 요소 컬렉션에서 만들어진 새로운 사용자 지정 바인딩을 반환합니다.

    // Create a CustomBinding and return it; otherwise, return null.
    return new CustomBinding(bec);
    

예제

다음은 앞의 절차에서 설명한 전체 메서드입니다.

// This method creates a CustomBinding that includes two tokens of a given type.
public static Binding CreateCustomBinding(EndpointAddress issuerEndpointAddress1, Binding issuerBinding1, EndpointAddress issuerEndpointAddress2, Binding issuerBinding2)
{
    // Create an empty BindingElementCollection to populate, 
    // then create a custom binding from it.
    BindingElementCollection bec = new BindingElementCollection();

    SecurityBindingElement sbe = SecurityBindingElement.CreateMutualCertificateBindingElement();

    SupportingTokenParameters supportParams = new SupportingTokenParameters();
    
    // Two supporting SAML tokens are being added.
    supportParams.SignedEndorsing.Add(new IssuedSecurityTokenParameters("samlTokenType", issuerEndpointAddress1, issuerBinding1));
    supportParams.SignedEndorsing.Add(new IssuedSecurityTokenParameters("samlTokenType", issuerEndpointAddress2, issuerBinding2));
    
    ((SymmetricSecurityBindingElement)sbe).OperationSupportingTokenParameters.Add("*", supportParams);
    
    bec.Add(sbe);
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());

    // Create a CustomBinding and return it; otherwise, return null.
    return new CustomBinding(bec);
}

참고 항목

개념

보안 아키텍처