C# Class GSF.Identity.UserInfo

Represents information about a local user or a domain user (e.g., from Active Directory).
See http://msdn.microsoft.com/en-us/library/ms677980.aspx for more information on active directory properties.
Inheritance: ISupportLifecycle, IPersistSettings
Mostrar archivo Open project: GridProtectionAlliance/gsf Class Usage Examples

Private Properties

Property Type Description
Dispose void
GetNameElements string[]
ValidateGroupName string

Public Methods

Method Description
AddUserToLocalGroup ( string groupName, string userName ) : bool

Adds an existing user to the specified local groupName.

This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also add Active Directory user accounts and groups to the local group the when the userName is prefixed with a domain name and a backslash "\".

AuthenticateUser ( string domain, string userName, string password ) : IPrincipal

Authenticates the specified user credentials.

This method always returns null under Mono deployments.

AuthenticateUser ( string domain, string userName, string password, string &errorMessage ) : IPrincipal

Authenticates the specified user credentials.

This method always returns null under Mono deployments.

ChangePassword ( string oldPassword, string newPassword ) : void

Attempts to change the user's password.

CreateLocalGroup ( string groupName, string groupDescription = null ) : bool

Creates a new local group if it does not exist already.

CreateLocalUser ( string userName, string password, string userDescription = null ) : bool

Creates a new local user if it does not exist already.

DefinePrivilegedAccount ( string domain, string username, string password ) : void

Defines the credentials of a privileged domain account that can be used for impersonation prior to the retrieval of user information from the Active Directory.

Dispose ( ) : void

Releases all the resources used by the UserInfo object.

EndImpersonation ( System.Security.Principal.WindowsImpersonationContext impersonatedUser ) : void

Ends the impersonation of the specified user.

GetBuiltInLocalGroups ( ) : string[]

Returns a sorted list of the common built-in local groups. On Windows these groups have a domain name of BUILTIN.

Names in this list will not have a "BUILTIN\" prefix.

GetLocalGroupUserList ( string groupName ) : string[]

Gets a list of users that exist in the specified local groupName.

GetUserPropertyValue ( string propertyName ) : string

Returns the value for specified active directory property.

GroupNameToSID ( string groupName ) : string

Converts the given group name to the SID corresponding to that name.

If the groupName cannot be converted to a SID, groupName will be the return value.

ImpersonatePrivilegedAccount ( ) : System.Security.Principal.WindowsImpersonationContext

Impersonates the defined privileged domain account.

This method always returns null under Mono deployments.

ImpersonateUser ( string domain, string userName, string password ) : System.Security.Principal.WindowsImpersonationContext

Impersonates the specified user.

After impersonating a user the code executes under the impersonated user's identity.

This method always returns null under Mono deployments.

Initialize ( ) : void

Initializes the UserInfo object.

IsGroupSID ( string sid ) : bool

Determines whether the given security identifier identifies a group.

IsLocalDomain ( string domain ) : bool

Determines if specified domain is the local domain (i.e., local machine).

IsUserSID ( string sid ) : bool

Determines whether the given security identifier identifies a user account.

LoadSettings ( ) : void

Loads saved settings for the UserInfo object from the config file if the PersistSettings property is set to true.

LocalGroupExists ( string groupName ) : bool

Determines if local group exists.

LocalUserExists ( string userName ) : bool

Determines if local user exists.

RemoveLocalGroup ( string groupName ) : bool

Removes local group if it exists.

RemoveLocalUser ( string userName ) : bool

Removes local user if it exists.

RemoveUserFromLocalGroup ( string groupName, string userName ) : bool

Removes an existing user from the specified local groupName.

This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also remove Active Directory user accounts and groups from the local group the when the userName is prefixed with a domain name and a backslash "\".

SIDToAccountName ( string sid ) : string

Converts the given SID to the corresponding account name.

If the sid cannot be converted to an account name, sid will be the return value.

SaveSettings ( ) : void

Saves settings for the UserInfo object to the config file if the PersistSettings property is set to true.

SetLocalUserPassword ( string userName, string password ) : void

Sets local user's password.

UserInfo ( string loginID ) : System

Initializes a new instance of the UserInfo class.

UserInfo ( string loginID, string ldapPath ) : System

Initializes a new instance of the UserInfo class.

UserIsInLocalGroup ( string groupName, string userName ) : bool

Determines if user is in the specified local groupName.

This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also detect Active Directory user accounts and groups that may exist in the local group when the userName is prefixed with a domain name and a backslash "\".

UserNameToSID ( string userName ) : string

Converts the given user name to the SID corresponding to that name.

If the userName cannot be converted to a SID, userName will be the return value.

Private Methods

Method Description
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the UserInfo object and optionally releases the managed resources.

GetNameElements ( string displayName ) : string[]
ValidateGroupName ( string groupName ) : string

Method Details

AddUserToLocalGroup() public static method

Adds an existing user to the specified local groupName.
This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also add Active Directory user accounts and groups to the local group the when the userName is prefixed with a domain name and a backslash "\".
or was null. No or was specified. Could not add user to local group.
public static AddUserToLocalGroup ( string groupName, string userName ) : bool
groupName string Group name to add local user to.
userName string Existing local user name.
return bool

AuthenticateUser() public static method

Authenticates the specified user credentials.
This method always returns null under Mono deployments.
public static AuthenticateUser ( string domain, string userName, string password ) : IPrincipal
domain string Domain of user to authenticate.
userName string Username of user to authenticate.
password string Password of user to authenticate.
return IPrincipal

AuthenticateUser() public static method

Authenticates the specified user credentials.
This method always returns null under Mono deployments.
public static AuthenticateUser ( string domain, string userName, string password, string &errorMessage ) : IPrincipal
domain string Domain of user to authenticate.
userName string Username of user to authenticate.
password string Password of user to authenticate.
errorMessage string Error message returned, if authentication fails.
return IPrincipal

ChangePassword() public method

Attempts to change the user's password.
public ChangePassword ( string oldPassword, string newPassword ) : void
oldPassword string Old password.
newPassword string New password.
return void

CreateLocalGroup() public static method

Creates a new local group if it does not exist already.
was null. No was specified. Could not create local group.
public static CreateLocalGroup ( string groupName, string groupDescription = null ) : bool
groupName string Group name to create if it doesn't exist.
groupDescription string Optional group description.
return bool

CreateLocalUser() public static method

Creates a new local user if it does not exist already.
or was null. No was specified. Could not create local user.
public static CreateLocalUser ( string userName, string password, string userDescription = null ) : bool
userName string User name to create if it doesn't exist.
password string Password to user for new user.
userDescription string Optional user description.
return bool

DefinePrivilegedAccount() public method

Defines the credentials of a privileged domain account that can be used for impersonation prior to the retrieval of user information from the Active Directory.
public DefinePrivilegedAccount ( string domain, string username, string password ) : void
domain string Domain of privileged domain user account.
username string Username of privileged domain user account.
password string Password of privileged domain user account.
return void

Dispose() public method

Releases all the resources used by the UserInfo object.
public Dispose ( ) : void
return void

EndImpersonation() public static method

Ends the impersonation of the specified user.
public static EndImpersonation ( System.Security.Principal.WindowsImpersonationContext impersonatedUser ) : void
impersonatedUser System.Security.Principal.WindowsImpersonationContext of the impersonated user.
return void

GetBuiltInLocalGroups() public static method

Returns a sorted list of the common built-in local groups. On Windows these groups have a domain name of BUILTIN.
Names in this list will not have a "BUILTIN\" prefix.
public static GetBuiltInLocalGroups ( ) : string[]
return string[]

GetLocalGroupUserList() public static method

Gets a list of users that exist in the specified local groupName.
was null. No was specified. Could not get members for local group.
public static GetLocalGroupUserList ( string groupName ) : string[]
groupName string Group name to remove local user from.
return string[]

GetUserPropertyValue() public method

Returns the value for specified active directory property.
public GetUserPropertyValue ( string propertyName ) : string
propertyName string Name of the active directory property whose value is to be retrieved.
return string

GroupNameToSID() public static method

Converts the given group name to the SID corresponding to that name.
If the groupName cannot be converted to a SID, groupName will be the return value.
public static GroupNameToSID ( string groupName ) : string
groupName string The group name for which to look up the SID.
return string

ImpersonatePrivilegedAccount() public method

Impersonates the defined privileged domain account.
This method always returns null under Mono deployments.
public ImpersonatePrivilegedAccount ( ) : System.Security.Principal.WindowsImpersonationContext
return System.Security.Principal.WindowsImpersonationContext

ImpersonateUser() public static method

Impersonates the specified user.

After impersonating a user the code executes under the impersonated user's identity.

This method always returns null under Mono deployments.

public static ImpersonateUser ( string domain, string userName, string password ) : System.Security.Principal.WindowsImpersonationContext
domain string Domain of user to impersonate.
userName string Username of user to impersonate.
password string Password of user to impersonate.
return System.Security.Principal.WindowsImpersonationContext

Initialize() public method

Initializes the UserInfo object.
Failed to initialize directory entry for .
public Initialize ( ) : void
return void

IsGroupSID() public static method

Determines whether the given security identifier identifies a group.
public static IsGroupSID ( string sid ) : bool
sid string The security identifier.
return bool

IsLocalDomain() public static method

Determines if specified domain is the local domain (i.e., local machine).
public static IsLocalDomain ( string domain ) : bool
domain string Domain name to check.
return bool

IsUserSID() public static method

Determines whether the given security identifier identifies a user account.
public static IsUserSID ( string sid ) : bool
sid string The security identifier.
return bool

LoadSettings() public method

Loads saved settings for the UserInfo object from the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public LoadSettings ( ) : void
return void

LocalGroupExists() public static method

Determines if local group exists.
was null. No was specified.
public static LocalGroupExists ( string groupName ) : bool
groupName string Group name to test for existence.
return bool

LocalUserExists() public static method

Determines if local user exists.
was null. No was specified.
public static LocalUserExists ( string userName ) : bool
userName string User name to test for existence.
return bool

RemoveLocalGroup() public static method

Removes local group if it exists.
was null. No was specified. Could not remove local group.
public static RemoveLocalGroup ( string groupName ) : bool
groupName string Group name to remove if it exists.
return bool

RemoveLocalUser() public static method

Removes local user if it exists.
was null. No was specified. Could not remove local user.
public static RemoveLocalUser ( string userName ) : bool
userName string User name to remove if it exists.
return bool

RemoveUserFromLocalGroup() public static method

Removes an existing user from the specified local groupName.
This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also remove Active Directory user accounts and groups from the local group the when the userName is prefixed with a domain name and a backslash "\".
or was null. No or was specified. Could not remove user from local group.
public static RemoveUserFromLocalGroup ( string groupName, string userName ) : bool
groupName string Group name to remove local user from.
userName string Existing local user name.
return bool

SIDToAccountName() public static method

Converts the given SID to the corresponding account name.
If the sid cannot be converted to an account name, sid will be the return value.
public static SIDToAccountName ( string sid ) : string
sid string The SID for which to look up the account name.
return string

SaveSettings() public method

Saves settings for the UserInfo object to the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public SaveSettings ( ) : void
return void

SetLocalUserPassword() public static method

Sets local user's password.
or was null. No was specified or user does not exist. Could not set password for local user.
public static SetLocalUserPassword ( string userName, string password ) : void
userName string User name to change password for.
password string New password fro user.
return void

UserInfo() public method

Initializes a new instance of the UserInfo class.
is a null or empty string.
public UserInfo ( string loginID ) : System
loginID string /// Login ID in 'domain\username' format of the user's account whose information is to be retrieved. Login ID /// can also be specified in 'username' format without the domain name, in which case the domain name will be /// approximated based on the privileged user domain if specified, default logon domain of the host machine /// if available, or the domain of the identity that owns the host process. ///
return System

UserInfo() public method

Initializes a new instance of the UserInfo class.
is a null or empty string.
public UserInfo ( string loginID, string ldapPath ) : System
loginID string /// Login ID in 'domain\username' format of the user's account whose information is to be retrieved. Login ID /// can also be specified in 'username' format without the domain name, in which case the domain name will be /// approximated based on the privileged user domain if specified, default logon domain of the host machine /// if available, or the domain of the identity that owns the host process. ///
ldapPath string /// String in 'LDAP://' format that specifies the Active Directory node where search for the user starts. ///
return System

UserIsInLocalGroup() public static method

Determines if user is in the specified local groupName.
This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also detect Active Directory user accounts and groups that may exist in the local group when the userName is prefixed with a domain name and a backslash "\".
or was null. No or was specified. Could not determine if user was in local group.
public static UserIsInLocalGroup ( string groupName, string userName ) : bool
groupName string Group name to test.
userName string User name to test.
return bool

UserNameToSID() public static method

Converts the given user name to the SID corresponding to that name.
If the userName cannot be converted to a SID, userName will be the return value.
public static UserNameToSID ( string userName ) : string
userName string The user name for which to look up the SID.
return string