C# Класс 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.
Наследование: ISupportLifecycle, IPersistSettings
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
Dispose void
GetNameElements string[]
ValidateGroupName string

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

AddUserToLocalGroup() публичный статический метод

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.
Результат bool

AuthenticateUser() публичный статический метод

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.
Результат IPrincipal

AuthenticateUser() публичный статический метод

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.
Результат IPrincipal

ChangePassword() публичный метод

Attempts to change the user's password.
public ChangePassword ( string oldPassword, string newPassword ) : void
oldPassword string Old password.
newPassword string New password.
Результат void

CreateLocalGroup() публичный статический метод

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.
Результат bool

CreateLocalUser() публичный статический метод

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.
Результат bool

DefinePrivilegedAccount() публичный метод

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.
Результат void

Dispose() публичный метод

Releases all the resources used by the UserInfo object.
public Dispose ( ) : void
Результат void

EndImpersonation() публичный статический метод

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.
Результат void

GetBuiltInLocalGroups() публичный статический метод

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[]
Результат string[]

GetLocalGroupUserList() публичный статический метод

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.
Результат string[]

GetUserPropertyValue() публичный метод

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.
Результат string

GroupNameToSID() публичный статический метод

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.
Результат string

ImpersonatePrivilegedAccount() публичный метод

Impersonates the defined privileged domain account.
This method always returns null under Mono deployments.
public ImpersonatePrivilegedAccount ( ) : System.Security.Principal.WindowsImpersonationContext
Результат System.Security.Principal.WindowsImpersonationContext

ImpersonateUser() публичный статический метод

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.
Результат System.Security.Principal.WindowsImpersonationContext

Initialize() публичный метод

Initializes the UserInfo object.
Failed to initialize directory entry for .
public Initialize ( ) : void
Результат void

IsGroupSID() публичный статический метод

Determines whether the given security identifier identifies a group.
public static IsGroupSID ( string sid ) : bool
sid string The security identifier.
Результат bool

IsLocalDomain() публичный статический метод

Determines if specified domain is the local domain (i.e., local machine).
public static IsLocalDomain ( string domain ) : bool
domain string Domain name to check.
Результат bool

IsUserSID() публичный статический метод

Determines whether the given security identifier identifies a user account.
public static IsUserSID ( string sid ) : bool
sid string The security identifier.
Результат bool

LoadSettings() публичный метод

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
Результат void

LocalGroupExists() публичный статический метод

Determines if local group exists.
was null. No was specified.
public static LocalGroupExists ( string groupName ) : bool
groupName string Group name to test for existence.
Результат bool

LocalUserExists() публичный статический метод

Determines if local user exists.
was null. No was specified.
public static LocalUserExists ( string userName ) : bool
userName string User name to test for existence.
Результат bool

RemoveLocalGroup() публичный статический метод

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.
Результат bool

RemoveLocalUser() публичный статический метод

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.
Результат bool

RemoveUserFromLocalGroup() публичный статический метод

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.
Результат bool

SIDToAccountName() публичный статический метод

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.
Результат string

SaveSettings() публичный метод

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
Результат void

SetLocalUserPassword() публичный статический метод

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.
Результат void

UserInfo() публичный метод

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. ///
Результат System

UserInfo() публичный метод

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. ///
Результат System

UserIsInLocalGroup() публичный статический метод

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.
Результат bool

UserNameToSID() публичный статический метод

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.
Результат string