[[Open棟梁>https://github.com/OpenTouryoProject]] wiki
「[[Open棟梁 wiki>https://opentouryo.osscons.jp]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-[[戻る>IdentityImpersonation]]

*目次 [#x05788f7]
#contents

*概要 [#s3e7414f]

区間偽装のサンプルです。

Open棟梁の[[IdentityImpersonation]].[[ImpersonateValidUser+UndoImpersonationメソッド>https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/Util/IdentityImpersonation.cs#L144]]を使用しています。
Open棟梁の[[IdentityImpersonation]].[[ImpersonateValidUser>https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Security/IdentityImpersonation.cs#L128]]+[[UndoImpersonation>https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Security/IdentityImpersonation.cs#L220]]メソッドを使用しています。

 try
 {
     // コードの特定部分を実行するときのみ、任意のユーザを偽装する。
 
     // 偽装して
     ii = new IdentityImpersonation();
     ret = ii.ImpersonateValidUser("x", "", "x");
 
     // ファイルを開く
     Console.WriteLine(
       string.Format("ユーザ「{0}」を偽装):", WindowsIdentity.GetCurrent().Name)
       + ResourceLoader.LoadAsString(@"c:\test.txt", Encoding.GetEncoding(CustomEncode.UTF_8)));
 
 }
 catch (Exception ex)
 {
     Debug.WriteLine(ex.Message);
 }
 finally
 {
     // 偽装解除
     ret = ii.UndoImpersonation();
 }


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS