Show / Hide Table of Contents

Class WindowsIdentityHelper

Utility class for WindowsIdentity

Inheritance
Object
WindowsIdentityHelper
Namespace: SuperOffice.Security.Util
Assembly: SoCore.dll
Syntax
public sealed class WindowsIdentityHelper : Object

Methods

GetErrorMessage()

Get an error message through the underlying Platform SDK.

Declaration
public static string GetErrorMessage()
Returns
Type Description
String

Error message as returned from the operating system.

LogonUser(String, String, String, WindowsIdentityHelper.LogonType, WindowsIdentityHelper.LogonProvider)

The LogonUser function attempts to log a user on to the local computer, that is, to the computer from which LogonUser was called. You cannot use LogonUser to log on to a remote computer. You specify the user with a user name and domain, and authenticate the user with a clear-text password. If the function succeeds, you receive a WindowsIdentity that represents the logged-on user.

Declaration
public static WindowsIdentity LogonUser(string userName, string domain, string password, WindowsIdentityHelper.LogonType logonType, WindowsIdentityHelper.LogonProvider logonProvider)
Parameters
Type Name Description
String userName

This is the name of the user account to log on to. If you use the UPN format, user@DNS_domain_name, the domain parameter must be null. If the username is empty this method will return the WindowsIdentity of the current user.

String domain

If this parameter is NULL, the user name must be specified in UPN format. If this parameter is ".", the function validates the account using only the local account database.

String password

Clear-text password for the user account specified by userName.

WindowsIdentityHelper.LogonType logonType

Specifies the type of logon operation to perform.

WindowsIdentityHelper.LogonProvider logonProvider

Specifies the logon provider.

Returns
Type Description
WindowsIdentity

WindowsIdentity representing the logged on user

Remarks

For further reference, se the platform SDK (e.g. Advapi32.lib and advapi32.dll) for method LogonUser.

Examples

Example of using this method to impersonate a user:

WindowsIdentity tmpUser = WindowsIdentityHelper.LogonUser
                          (
                            myUserName, 
                            myDomain, 
                            myPassword, 
                            WindowsIdentityHelper.LogonType.NetworkCleartext
                            WindowsIdentityHelper.LogonProvider.Default
                          );
WindowsImpersonationContext wic = tmpUser.Impersonate();

// Do my stuff as someone else

wic.Undo()
Exceptions
Type Condition
WindowsIdentityHelper.WindowsIdentityHelperException

Thrown if the user fails to log on.

TryLogonUser(String, String, String, WindowsIdentityHelper.LogonType, WindowsIdentityHelper.LogonProvider)

Attempt to log on to the local computer. Same functionality as SuperOffice.Security.Util.WindowsIdentityHelper.LogonUser(System.String,System.String,System.String,System.Int32,System.Int32,System.Int32@), but does not throw exceptions on failure (null return)

Declaration
public static WindowsIdentity TryLogonUser(string userName, string domain, string password, WindowsIdentityHelper.LogonType logonType, WindowsIdentityHelper.LogonProvider logonProvider)
Parameters
Type Name Description
String userName

This is the name of the user account to log on to. If you use the UPN format, user@DNS_domain_name, the domain parameter must be null.

String domain

If this parameter is NULL, the user name must be specified in UPN format. If this parameter is ".", the function validates the account using only the local account database.

String password

Clear-text password for the user account specified by userName.

WindowsIdentityHelper.LogonType logonType

Specifies the type of logon operation to perform.

WindowsIdentityHelper.LogonProvider logonProvider

Specifies the logon provider.

Returns
Type Description
WindowsIdentity

WindowsIdentity representing the logged on user; or null if the logon failed for any reason

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top