メモなので、確認はしていません。m(_ _)m
1.WCFサービスで偽装の設定をする
サービスメソッドで次のようにOperationBehavior.Impersonationの値を設定します。ImpersonationOption.Requiredで偽装が行われることを指定します。他の値Allowed,NotAllowedについてはMSDNのヘルプを参照して下さい。
[PrincipalPermission(SecurityAction.Demand, Role="WCFTestUsers")] [OperationBehavior(Impersonation=System.ServiceModel.ImpersonationOption.Required)] public List<int> GetProductIDs() { List<int> productIDs = new List<int>(); ... }
サービスメソッドすべてで偽装を行う場合はServiceAuthorizationBehavior.ImpersonateCallerForAllOperationsをtrueにします。構成ファイルで設定するには以下のように指定します。
<system.serviceModel> .... <services> <service behaviorConfiguration="ProductServiceBehavior" name="WCFSample.ProductService.ProductService"> <endpoint address="http://localhost:8056/ProductService" binding="basicHttpBinding" bindingConfiguration="ProductServiceBasicHttpBinding" contract="WCFSample.ProductService.IProductService" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ProductServiceBehavior"> <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8056/ProductService/Mex" /> <serviceAuthorization impersonateCallerForAllOperations="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
2.WCFクライアントで偽装のレベルを指定する
クライアントアプリケーションの構成ファイルで偽装のレベルを指定できます。WindowsClientCredential.AllowedImpersonationLevelを設定しますTokenImpersonationLevel列挙型の説明はMSDNを参照して下さい。構成ファイル上で設定するには次のように行います。
<system.serviceModel> ... <client> <endpoint address="http://localhost:8056/ProductService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ProductService" contract="WCFSample.Client.Proxy.ProductService" name="BasicHttpBinding_ProductService" behaviorConfiguration="ProductServiceBehavior" /> </client> <behaviors> <endpointBehaviors> <behavior name="ProductServiceBehavior"> <clientCredentials> <windows allowedImpersonationLevel="Delegation"/> </clientCredentials> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel>
偽装についてのメモは終了です。設定値に関する詳細はMSDNを参照して下さい。
間違い、ご指摘等ありましたら連絡くださいませ。追記:ためしてみたらうまくいかないっぽいので、調べたら書き直します。
さんのコメント: さんのコメント: