Class SoImpersonationContext
Utility class assisting with impersonation. Impersonation is only permitted if a system user is logged in using CRM5 username and password and the user that is impersonated is an employee or external person.
Implements
Inherited Members
Namespace: SuperOffice.Security
Assembly: SoCore.dll
Syntax
public sealed class SoImpersonationContext : IDisposable
Properties
ImpersonatedPrincipal
Principal of the impersonated user.
Declaration
public ClaimsPrincipal ImpersonatedPrincipal { get; }
Property Value
| Type | Description |
|---|---|
| ClaimsPrincipal |
RealPrincipal
Principle of the impersonating user.
Declaration
public ClaimsPrincipal RealPrincipal { get; }
Property Value
| Type | Description |
|---|---|
| ClaimsPrincipal |
Methods
CanImpersonate()
Check if the currently logged in user is permitted to impersonate.
Declaration
public static bool CanImpersonate()
Returns
| Type | Description |
|---|---|
| bool | True if the currently logged in user is permitted to impersonate. |
CanImpersonate(ClaimsPrincipal)
Check if the user represented by the provided principle is permitted to impersonate.
Declaration
public static bool CanImpersonate(ClaimsPrincipal impersonator)
Parameters
| Type | Name | Description |
|---|---|---|
| ClaimsPrincipal | impersonator | The user to check if it has the permission to impersonate |
Returns
| Type | Description |
|---|---|
| bool | True if the user represented by the provided principle is permitted to impersonate. |
Dispose()
Dispose of the temporary user context
Declaration
public void Dispose()
Impersonate(string)
Impersonate as the user with the provided user name. Only users of type System logged in with username and passwords are permitted to impersonate. Call Dispose() or SoImpersonationContext.Revert. Impersonation is not supported with remote mode.
Declaration
public static SoImpersonationContext Impersonate(string user)
Parameters
| Type | Name | Description |
|---|---|---|
| string | user | Name of the user to impersonate as. |
Returns
| Type | Description |
|---|---|
| SoImpersonationContext | Disposable context for the impersonation. |
Remarks
Impersonation lives in the thread scope. It is not permitted to log out using Close() or in any other way end the current session like calling SoSession.Suspend while in a impersonated state.