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
Afficher le fichier Open project: GridProtectionAlliance/gsf Class Usage Examples

Private Properties

Свойство Type Description
Dispose void
GetNameElements string[]
ValidateGroupName string

Méthodes publiques

Méthode 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

Méthode 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 méthode

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.
Résultat bool

AuthenticateUser() public static méthode

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.
Résultat IPrincipal

AuthenticateUser() public static méthode

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.
Résultat IPrincipal

ChangePassword() public méthode

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

CreateLocalGroup() public static méthode

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.
Résultat bool

CreateLocalUser() public static méthode

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.
Résultat bool

DefinePrivilegedAccount() public méthode

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.
Résultat void

Dispose() public méthode

Releases all the resources used by the UserInfo object.
public Dispose ( ) : void
Résultat void

EndImpersonation() public static méthode

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.
Résultat void

GetBuiltInLocalGroups() public static méthode

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[]
Résultat string[]

GetLocalGroupUserList() public static méthode

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.
Résultat string[]

GetUserPropertyValue() public méthode

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.
Résultat string

GroupNameToSID() public static méthode

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.
Résultat string

ImpersonatePrivilegedAccount() public méthode

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

ImpersonateUser() public static méthode

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.
Résultat System.Security.Principal.WindowsImpersonationContext

Initialize() public méthode

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

IsGroupSID() public static méthode

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

IsLocalDomain() public static méthode

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

IsUserSID() public static méthode

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

LoadSettings() public méthode

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
Résultat void

LocalGroupExists() public static méthode

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

LocalUserExists() public static méthode

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

RemoveLocalGroup() public static méthode

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.
Résultat bool

RemoveLocalUser() public static méthode

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.
Résultat bool

RemoveUserFromLocalGroup() public static méthode

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.
Résultat bool

SIDToAccountName() public static méthode

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.
Résultat string

SaveSettings() public méthode

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
Résultat void

SetLocalUserPassword() public static méthode

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.
Résultat void

UserInfo() public méthode

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. ///
Résultat System

UserInfo() public méthode

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. ///
Résultat System

UserIsInLocalGroup() public static méthode

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.
Résultat bool

UserNameToSID() public static méthode

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.
Résultat string