tgstation-server 6.19.2
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Public Member Functions | Properties | Private Attributes | List of all members
Tgstation.Server.Host.Security.WindowsSystemIdentity Class Referencesealed

ISystemIdentity for windows systems. More...

Inheritance diagram for Tgstation.Server.Host.Security.WindowsSystemIdentity:
Inheritance graph
[legend]
Collaboration diagram for Tgstation.Server.Host.Security.WindowsSystemIdentity:
Collaboration graph
[legend]

Public Member Functions

 WindowsSystemIdentity (WindowsIdentity identity)
 Initializes a new instance of the WindowsSystemIdentity class.
 
 WindowsSystemIdentity (UserPrincipal userPrincipal)
 Initializes a new instance of the WindowsSystemIdentity class.
 
void Dispose ()
 
ISystemIdentity Clone ()
 Clone the ISystemIdentity creating another copy that must have IDisposable.Dispose called on it.
Returns
A new ISystemIdentity mirroring the current one.

 
Task RunImpersonated (Action action, CancellationToken cancellationToken)
 Runs a given action in the context of the ISystemIdentity.
Parameters
actionThe Action to perform, should be simple and not use any Tasks or threading.
cancellationTokenThe CancellationToken for the operation.
Returns
A Task representing the running operation.

 

Properties

string Uid [get]
 A unique identifier for the user.
 
string Username [get]
 The user's name.
 
bool CanCreateSymlinks [get]
 If this system identity has permissions to create symlinks.
 
bool IsSuperUser [get]
 Is this identity a SuperUser for the OS. See Administrator on Windows or root on Linux.
 
- Properties inherited from Tgstation.Server.Host.Security.ISystemIdentity

Private Attributes

readonly? WindowsIdentity identity
 The WindowsIdentity for the WindowsSystemIdentity.
 
readonly? UserPrincipal userPrincipal
 The UserPrincipal for the WindowsSystemIdentity.
 
readonly? bool isAdmin
 Backing field for IsSuperUser.
 

Detailed Description

ISystemIdentity for windows systems.

Definition at line 16 of file WindowsSystemIdentity.cs.

Constructor & Destructor Documentation

◆ WindowsSystemIdentity() [1/2]

Tgstation.Server.Host.Security.WindowsSystemIdentity.WindowsSystemIdentity ( WindowsIdentity  identity)

Initializes a new instance of the WindowsSystemIdentity class.

Parameters
identityThe value of identity.

Definition at line 49 of file WindowsSystemIdentity.cs.

50 {
51 this.identity = identity ?? throw new ArgumentNullException(nameof(identity));
52 if (identity.IsAnonymous)
53 throw new ArgumentException($"Cannot use anonymous {nameof(WindowsIdentity)} as a {nameof(WindowsSystemIdentity)}!", nameof(identity));
54
55 isAdmin = new WindowsPrincipal(identity).IsInRole(WindowsBuiltInRole.Administrator);
56 }
readonly? bool isAdmin
Backing field for IsSuperUser.
readonly? WindowsIdentity identity
The WindowsIdentity for the WindowsSystemIdentity.

References Tgstation.Server.Host.Security.WindowsSystemIdentity.identity, and Tgstation.Server.Host.Security.WindowsSystemIdentity.isAdmin.

◆ WindowsSystemIdentity() [2/2]

Tgstation.Server.Host.Security.WindowsSystemIdentity.WindowsSystemIdentity ( UserPrincipal  userPrincipal)

Initializes a new instance of the WindowsSystemIdentity class.

Parameters
userPrincipalThe value of userPrincipal.

Definition at line 62 of file WindowsSystemIdentity.cs.

63 {
64 this.userPrincipal = userPrincipal ?? throw new ArgumentNullException(nameof(userPrincipal));
65 }
readonly? UserPrincipal userPrincipal
The UserPrincipal for the WindowsSystemIdentity.

References Tgstation.Server.Host.Security.WindowsSystemIdentity.userPrincipal.

Member Function Documentation

◆ Clone()

ISystemIdentity Tgstation.Server.Host.Security.WindowsSystemIdentity.Clone ( )

Clone the ISystemIdentity creating another copy that must have IDisposable.Dispose called on it.

Returns
A new ISystemIdentity mirroring the current one.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

Definition at line 81 of file WindowsSystemIdentity.cs.

82 {
83 if (identity != null)
84 {
85 // var newIdentity = (WindowsIdentity)identity.Clone(); //doesn't work because of https://github.com/dotnet/corefx/issues/31841
86 var newIdentity = new WindowsIdentity(identity.Token); // the handle is cloned internally
87
88 return new WindowsSystemIdentity(newIdentity);
89 }
90
91 // can't clone a UP, shouldn't be trying to anyway, cloning is for impersonation
92 throw new NotSupportedException("Cannot clone a UserPrincipal based WindowsSystemIdentity!");
93 }
WindowsSystemIdentity(WindowsIdentity identity)
Initializes a new instance of the WindowsSystemIdentity class.

References Tgstation.Server.Host.Security.WindowsSystemIdentity.identity.

◆ Dispose()

void Tgstation.Server.Host.Security.WindowsSystemIdentity.Dispose ( )

Definition at line 68 of file WindowsSystemIdentity.cs.

69 {
70 if (identity != null)
71 identity.Dispose();
72 else
73 {
74 var context = userPrincipal!.Context;
75 userPrincipal.Dispose();
76 context.Dispose();
77 }
78 }

References Tgstation.Server.Host.Security.WindowsSystemIdentity.identity, and Tgstation.Server.Host.Security.WindowsSystemIdentity.userPrincipal.

◆ RunImpersonated()

Task Tgstation.Server.Host.Security.WindowsSystemIdentity.RunImpersonated ( Action  action,
CancellationToken  cancellationToken 
)

Runs a given action in the context of the ISystemIdentity.

Parameters
actionThe Action to perform, should be simple and not use any Tasks or threading.
cancellationTokenThe CancellationToken for the operation.
Returns
A Task representing the running operation.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

References Tgstation.Server.Host.Security.WindowsSystemIdentity.identity.

Member Data Documentation

◆ identity

readonly? WindowsIdentity Tgstation.Server.Host.Security.WindowsSystemIdentity.identity
private

◆ isAdmin

readonly? bool Tgstation.Server.Host.Security.WindowsSystemIdentity.isAdmin
private

Backing field for IsSuperUser.

Definition at line 43 of file WindowsSystemIdentity.cs.

Referenced by Tgstation.Server.Host.Security.WindowsSystemIdentity.WindowsSystemIdentity().

◆ userPrincipal

readonly? UserPrincipal Tgstation.Server.Host.Security.WindowsSystemIdentity.userPrincipal
private

Property Documentation

◆ CanCreateSymlinks

bool Tgstation.Server.Host.Security.WindowsSystemIdentity.CanCreateSymlinks
get

If this system identity has permissions to create symlinks.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

Definition at line 25 of file WindowsSystemIdentity.cs.

◆ IsSuperUser

bool Tgstation.Server.Host.Security.WindowsSystemIdentity.IsSuperUser
get

Is this identity a SuperUser for the OS. See Administrator on Windows or root on Linux.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

Definition at line 28 of file WindowsSystemIdentity.cs.

◆ Uid

string Tgstation.Server.Host.Security.WindowsSystemIdentity.Uid
get

A unique identifier for the user.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

Definition at line 19 of file WindowsSystemIdentity.cs.

◆ Username

string Tgstation.Server.Host.Security.WindowsSystemIdentity.Username
get

The user's name.

Implements Tgstation.Server.Host.Security.ISystemIdentity.

Definition at line 22 of file WindowsSystemIdentity.cs.


The documentation for this class was generated from the following file: