WCF セキュリティ トークン サービス

Visual Studio で、[ファイル] メニューを開き、[新規作成]、[Web サイト] の順に選択します。 WCF セキュリティ トークン サービスを選択します。

web.config ファイルを見ると、通常の ASP.NET Web サイトの web.config とは多くの違いがあることがわかります。

  • 次のアプリケーション設定が追加されています。

    <appSettings> <add key="IssuerName" value="PassiveSigninSTS"/> <add key="SigningCertificateName" value="CN=STSTestCert"/> <add key="EncryptingCertificateName" value=""/> </appSettings>
    

    STS は既定の証明書を使用して、発行するトークンに署名します。 この証明書の名前は "STSTestCert" で、STS で使用するために証明書ストアに自動的に追加されます。 証明書ファイルは STS プロジェクト内にあります。 ファイルのパスワードは "STSTest" です。 これは、運用時には使用しないでください。 既定の証明書を任意の他の証明書に変更することができます。 IIS プロセスのユーザーがその証明書の秘密キーにアクセスできることを確認してください。 また、IssuerNameRegistry の派生型を作成して、信頼できる発行者の証明書の検証もプログラムで実行します。

  • すべてのユーザーに、フェデレーション メタデータへのアクセス権が付与されます。 フェデレーション メタデータには、トークン署名証明書の公開キー、STS によって公開されるエンドポイント、および発行される要求に関する情報が含まれます。

    <location path="FederationMetadata"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> </location>
    
  • <system.Web>/<assemblies> 要素には、Microsoft.IdentityModel.dll アセンブリへの参照が含まれています。

    <add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    
  • 認証が、"Windows" から "None" に変更されています。

    <authentication mode="None">
    
  • 認証サービス、プロファイル サービス、および役割サービスが追加されています。

    <system.web.extensions> <scripting> <webServices> <!-- Uncomment this section to enable the authentication service. Include requireSSL="true" if appropriate. <authenticationService enabled="true" requireSSL = "true|false"/> --> <!-- Uncomment these lines to enable the profile service, and to choose the profile properties that can be retrieved and modified in ASP.NET AJAX applications. <profileService enabled="true" readAccessProperties="propertyname1,propertyname2" writeAccessProperties="propertyname1,propertyname2" /> --> <!-- Uncomment this section to enable the role service. <roleService enabled="true"/> --> </webServices> <!-- <scriptResourceHandler enableCompression="true" enableCaching="true" /> --> </scripting> </system.web.extensions>
    
  • 次のサービス、エンドポイント、バインド、および動作が追加されています。

    <system.serviceModel> <services> <service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract" behaviorConfiguration="ServiceBehavior"> <endpoint address="IWSTrust13" binding="ws2007HttpBinding" contract="Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract"  bindingConfiguration="ws2007HttpBindingConfiguration"/> <host> <baseAddresses> <add baseAddress="https://localhost/STSService1/Service.svc" /> </baseAddresses> </host> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <ws2007HttpBinding> <binding name="ws2007HttpBindingConfiguration"> <security mode="Message"> <message establishSecurityContext="false" /> </security> </binding> </ws2007HttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true" /> <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
    
  • トレースが追加されています。コメントを外すことで、トレースを有効にすることができます。 詳細については、「WIF トレース」および「トレースを有効にする方法」を参照してください。

    <!-- Uncomment the lines below to enable WIF tracing to: WIFTrace.e2e. Open the trace file using the SvcTraceViewer.exe tool (shipped with the WCF SDK available from Microsoft) or a xml viewer. Refer to MSDN if you wish to add WCF tracing. -->
    
      <!--<system.diagnostics> <sources> <source name="Microsoft.IdentityModel" switchValue="Verbose"> <listeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="WIFTrace.e2e" /> </listeners> </source> </sources> <trace autoflush="true" /> </system.diagnostics>-->
    

App_Code フォルダーで、CustomSecurityTokenService.cs を開きます。

  • static readonly string[] ActiveClaimsAwareApps を更新して、この STS からのトークンの発行先である証明書利用者アプリケーションの URL を含めます。

  • GetOutputClaimsIdentity メソッドのオーバーライドで、STS から証明書利用者アプリケーションに発行する必要がある要求と、STS で発行する必要があるカスタム要求を追加します。

CustomSecurityTokenService.cs により、次の必要なメソッドが実装されます。

  1. GetScope。このメソッドは、呼び出し元の IClaimsPrincipal と、入力される RST を受け取り、トークン発行要求のための構成を返します。トークン発行要求は、Scope クラスで表されます。 このメソッドで、証明書利用者のアドレスを正規化し、署名キーと暗号化キーを選択できます。 通常、セキュリティ トークンは証明書利用者だけが読み取れるように暗号化されます。

  2. GetOutputClaimsIdentity。このメソッドは、呼び出し元の IClaimsPrincipal、入力される RST、および GetScope から返された Scope オブジェクトを受け取り、発行されるトークンに含まれる IClaimsIdentity を返します。 このメソッドを使用して、トークンに含まれる要求を判別できます。