WIF(Windows Identity Foundation)とWebファーム



Wif



Windows Identity Foundation(WIF)を使用するリソース(RP)アプリケーションの保護された証明書利用者Webファーム展開では、異なるコンピューターで実行されているトークン証明書利用者アプリケーションがWIFフィールドインスタンスを処理できるようにするために、特定の手順を実行する必要があります。セッショントークン署名の検証、暗号化と復号化のセッショントークン、および再生キャッシュセッショントークンセキュリティトークンの検出で構成されるプロセス。

通常の状況では、保護されたリソースのWIF依存パーティアプリケーション(RPが単一のコンピューターで実行されているかWebファームで実行されているかに関係なく)を使用すると、クライアントセッションでセキュリティトークンサービス(STS)セキュリティトークンから取得した基盤が作成されます。 。これは、STSでWIF保護を使用するアプリケーションリソースごとにクライアントに認証を強制することを回避するためです。 WIFセッションの処理方法の詳細については、を参照してください。 WIFセッション管理



デフォルト設定を使用する場合、WIFは次のことを行います。

  • それは使用しています SessionSecurityTokenHandler セッショントークンを読み書きするクラスの例( SessionSecurityToken クラスのインスタンス)、このセッショントークンパッシングステートメント、認証用の他の関連情報セキュリティトークン、およびセッション自体に関する情報。セッションCookieにパッケージ化および保存されたセッショントークン。デフォルトでは、 SessionSecurityTokenHandler 使用する ProtectedDataCookieTransform クラスは、データ保護API(DPAPI)で保護されたセッショントークンを使用します。 DPAPIユーザーまたはコンピューターの資格情報を使用して、ユーザープロファイルに保存されている重要なデータを保護します。
  • それは使用しています SessionSecurityTokenCache デフォルトのクラスは、メモリストレージと処理セッショントークンを実装します。

これらのデフォルト設定の依存パーティアプリケーションは、単一のコンピューターの作業プログラムにデプロイされますが、Webファームにデプロイされると、これらの処理例によって、各HTTP要求が異なるコンピューターで実行されている異なるインスタンスの証明書利用者アプリケーションに送信される場合があります。このシナリオでは、トークンとトークン保護は特定のコンピューターに依存するため、上記のデフォルト設定のWIFは機能しません。



証明書利用者アプリケーションをWebファームに展開するには、セッショントークン(トークンと再生)プロセスが特定のコンピューターで実行されるアプリケーションに依存しないようにする必要があります。 1つのアプローチは、ASP.NETConfiguration機能が提供する要素を使用し、分散キャッシングセッショントークンとトークンの再生を提供するように、証明書利用者アプリケーションを実装することです。 ByElementsは、認証、暗号化、および復号化キートークンを必要とする構成ファイルで指定できます。Webファーム内の異なるコンピューターで同じキーを指定できます。 WIF専用セッショントークンハンドラー MachineKeySessionSecurityTokenHandler ハンドラーは、要素トークンキー保護でSpecifiedを使用します。このポリシーを実装するには、次のガイドラインに従ってください。

  • ASP.NETを使用するconfigurationElementは、さまざまなコンピューターで使用される署名キーと暗号化キーの存在を明示的に指定できます。次のXMLは、profileUnderelementsSpecification要素を表示します。
[ServiceContract()] public interface ISessionSecurityTokenCacheService { [OperationContract] void AddOrUpdate(string endpointId, string contextId, string keyGeneration, SessionSecurityToken value, DateTime expiryTime) [OperationContract] IEnumerable GetAll(string endpointId, string contextId) [OperationContract] SessionSecurityToken Get(string endpointId, string contextId, string keyGeneration) [OperationContract(Name = 'RemoveAll')] void RemoveAll(string endpointId, string contextId) [OperationContract(Name = 'RemoveAllByEndpointId')] void RemoveAll(string endpointId) [OperationContract] void Remove(string endpointId, string contextId, string keyGeneration) } ISessionSecurityTokenCacheService
  • に由来する SessionSecurityTokenCache また、分散キャッシュの実装により、RPフィールドキャッシュからすべてのコンピューターアクセスを実行できます。構成ファイルを指定する RP分散キャッシュ構成要素。派生クラスは置換できます SessionSecurityTokenCache.LoadCustomConfiguration on-demandChild要素を実現するためのメソッド。
using System using System.Collections.Generic using System.IdentityModel.Configuration using System.IdentityModel.Tokens using System.ServiceModel using System.Xml namespace WcfSessionSecurityTokenCacheService { [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] public class SessionSecurityTokenCacheService : ISessionSecurityTokenCacheService { SessionSecurityTokenCache internalCache // sets the internal cache used by the service to the default WIF in-memory cache. public SessionSecurityTokenCacheService() { internalCache = new IdentityModelCaches().SessionSecurityTokenCache } ... public SessionSecurityToken Get(string endpointId, string contextId, string keyGeneration) { // Delegates to the default, in-memory MruSessionSecurityTokenCache used by WIF SessionSecurityToken token = internalCache.Get(new SessionSecurityTokenCacheKey(endpointId, GetContextId(contextId), GetKeyGeneration(keyGeneration))) return token } ... private static UniqueId GetContextId(string contextIdString) { return contextIdString == null ? null : new UniqueId(contextIdString) } private static UniqueId GetKeyGeneration(string keyGenerationString) { return keyGenerationString == null ? null : new UniqueId(keyGenerationString) } } }

1つの方法は、カスタムWCFフロントエンドキャッシュに分散キャッシュを提供することです。 WCFキャッシングサービスの実装の詳細については、を参照してください。 WCFキャッシュサービス 。証明書利用者アプリケーションの詳細の実装については、WCFクライアントキャッシュサービスを使用できます。を参照してください。 WCFクライアントキャッシュ

  • リプレイアプリケーションがトークンを検出した場合、トークンは分散キャッシュ戦略と同様のリプレイキャッシュである必要があります。 TokenReplayCache 派生し、 構成要素は、トークン再生キャッシュサービスを指します。

重要



このトピックのすべての例とXMLの抜粋 ClaimsAwareWebFarm 例。

重要

このトピックの例は、変更なしで本番コードで直接推奨されないために提供されています。

WCFキャッシュサービス

次のWCFインターフェイス定義キャッシングサービスと、使用されるWCFクライアント通信間のパーティ合意に依存するアプリケーション。それは本質的に公共サービス事業です SessionSecurityTokenCache クラスのメソッド。

ISessionSecurityTokenCacheService

次のコードは、WCFキャッシングサービスの実装を示しています。この例では、WIFによって実装されたデフォルトのセッショントークンキャッシュメモリを使用します。さらに、データベースを実装して、キャッシュの永続的なサポートを提供できます。using System using System.Configuration using System.IdentityModel.Configuration using System.IdentityModel.Tokens using System.ServiceModel using System.Xml namespace CacheLibrary { /// /// This class acts as a proxy to the WcfSessionSecurityTokenCacheService. /// public class SharedSessionSecurityTokenCache : SessionSecurityTokenCache, ICustomIdentityConfiguration { private ISessionSecurityTokenCacheService WcfSessionSecurityTokenCacheServiceClient internal SharedSessionSecurityTokenCache() { } /// /// Creates a client channel to call the service host. /// protected void Initialize(string cacheServiceAddress) { if (this.WcfSessionSecurityTokenCacheServiceClient != null) { return } ChannelFactory cf = new ChannelFactory( new WS2007HttpBinding(SecurityMode.None), new EndpointAddress(cacheServiceAddress)) this.WcfSessionSecurityTokenCacheServiceClient = cf.CreateChannel() } #region SessionSecurityTokenCache Members // Delegates the following operations to the centralized session security token cache service in the web farm. ... public override SessionSecurityToken Get(SessionSecurityTokenCacheKey key) { return this.WcfSessionSecurityTokenCacheServiceClient.Get(key.EndpointId, GetContextIdString(key), GetKeyGenerationString(key)) } ... #endregion #region ICustomIdentityConfiguration Members // Called from configuration infrastructure to load custom elements public void LoadCustomConfiguration(XmlNodeList nodeList) { // Retrieve the endpoint address of the centralized session security token cache service running in the web farm if (nodeList.Count == 0) { throw new ConfigurationException('No child config element found under .') } XmlElement cacheServiceAddressElement = nodeList.Item(0) as XmlElement if (cacheServiceAddressElement.LocalName != 'cacheServiceAddress') { throw new ConfigurationException('First child config element under is expected to be .') } string cacheServiceAddress = null if (cacheServiceAddressElement.Attributes['url'] != null) { cacheServiceAddress = cacheServiceAddressElement.Attributes['url'].Value } else { throw new ConfigurationException(' is expected to contain a 'url' attribute.') } // Initialize the proxy to the WebFarmSessionSecurityTokenCacheService this.Initialize(cacheServiceAddress) } #endregion private static string GetKeyGenerationString(SessionSecurityTokenCacheKey key) { return key.KeyGeneration == null ? null : key.KeyGeneration.ToString() } private static string GetContextIdString(SessionSecurityTokenCacheKey key) { return GetContextIdString(key.ContextId) } private static string GetContextIdString(UniqueId contextId) { return contextId == null ? null : contextId.ToString() } } } 上で定義されたインターフェース。この例では、簡潔にするために、インターフェースを実装するために必要なすべてのメソッドがデモンストレーションではありません。

WCFクライアントキャッシュ

このセクションでは、 SessionSecurityTokenCache そして、委託された実装は、キャッシングサービスクラスを呼び出します。沿って XMLに示されているように、そのようなアプリケーションを使用するために当事者に依存する構成要素

そのような代替 LoadCustomConfiguration サービスエンドポイントのカスタムelementSub要素からのメソッド。このエンドポイントを初期化とサービス通信に使用します

通路。この例では、簡潔にするために、デモを実現しませんでした SessionSecurityTokenCache すべてのクラスメソッドが必要です。

|_+_|