Identity of a thread
Assume Net process P
runs under windows account A1
. I assume if thread ( running within P
) is running under some other identity ( obtained via Thread.CurrentPrincipal.Identity
) than A1
, it still has the same rights as A开发者_JS百科1
when accessing system resources ( such as files etc )?
thank you
I would not expect a thread that has a different identity to "inherit" the permissions from the process identity.
Just to be sure I ran an impersonation test .Using the sample here WindowsIdentity.Impersonate I ran the following code on a different thread.
WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
Thread.CurrentPrincipal = new WindowsPrincipal(newId);
string foo = System.IO.File.ReadAllText (@"test.txt");
Console.WriteLine(foo);
Even though the ID of the process has rights to read test.txt it if the newID doesn't it fails.
精彩评论