2using System.DirectoryServices.AccountManagement;
3using System.Runtime.Versioning;
4using System.Security.Principal;
6using System.Threading.Tasks;
15 [SupportedOSPlatform(
"windows")]
51 this.identity =
identity ??
throw new ArgumentNullException(nameof(
identity));
53 throw new ArgumentException($
"Cannot use anonymous {nameof(WindowsIdentity)} as a {nameof(WindowsSystemIdentity)}!", nameof(
identity));
55 isAdmin =
new WindowsPrincipal(
identity).IsInRole(WindowsBuiltInRole.Administrator);
86 var newIdentity =
new WindowsIdentity(
identity.Token);
92 throw new NotSupportedException(
"Cannot clone a UserPrincipal based WindowsSystemIdentity!");
96 public Task
RunImpersonated(Action action, CancellationToken cancellationToken) => Task.Factory.StartNew(
99 ArgumentNullException.ThrowIfNull(action);
101 throw new NotSupportedException(
"Impersonate using a UserPrincipal based WindowsSystemIdentity!");
102 WindowsIdentity.RunImpersonated(
identity.AccessToken, action);
106 TaskScheduler.Current);
IIOManager that resolves paths to Environment.CurrentDirectory.
const TaskCreationOptions BlockingTaskCreationOptions
The TaskCreationOptions used to spawn Tasks for potentially long running, blocking operations.
ISystemIdentity for windows systems.
string Uid
A unique identifier for the user.
WindowsSystemIdentity(WindowsIdentity identity)
Initializes a new instance of the WindowsSystemIdentity class.
readonly? UserPrincipal userPrincipal
The UserPrincipal for the WindowsSystemIdentity.
string Username
The user's name.
WindowsSystemIdentity(UserPrincipal userPrincipal)
Initializes a new instance of the WindowsSystemIdentity class.
ISystemIdentity Clone()
Clone the ISystemIdentity creating another copy that must have IDisposable.Dispose called on it....
Task RunImpersonated(Action action, CancellationToken cancellationToken)
Runs a given action in the context of the ISystemIdentity.A Task representing the running operation.
bool CanCreateSymlinks
If this system identity has permissions to create symlinks.
readonly? bool isAdmin
Backing field for IsSuperUser.
readonly? WindowsIdentity identity
The WindowsIdentity for the WindowsSystemIdentity.
bool IsSuperUser
Is this identity a SuperUser for the OS. See Administrator on Windows or root on Linux.
Represents a user on the current global::System.Runtime.InteropServices.OSPlatform.