「[[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/CS/Frameworks/Infrastructure/Public/Security/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();
 }

IP:1.73.93.253 TIME:"2018-07-30 (月) 16:41:01" REFERER:"https://opentouryo.osscons.jp/index.php?cmd=edit&page=%E5%8C%BA%E9%96%93%E5%81%BD%E8%A3%85%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB" USER_AGENT:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS