Programming Microsoft Dynamics CRM 4.0: Plug-ins
- 12/15/2008
Impersonation
Impersonation in Microsoft Dynamics CRM occurs when a CrmService or MetadataService call is made on behalf of another user. Plug-ins have two options for impersonation. First, they can be registered to impersonate a specific user by default. Second, they can specify a user ID to impersonate on the fly during execution.
Impersonation During Registration
When you register a plug-in, you can specify an impersonatinguserid value. In this situation, any calls to the IPluginExecutionContext interface’s CreateCrmService or CreateMetadataService methods with a value of true for the useCurrentUser argument result in a service that is impersonating the user specified at registration. Passing false for the useCurrentUser argument results in a service that is executing as the “system” user. In addition, the IPluginExecutionContext interface’s UserId property contains the user ID specified during registration.
Impersonation During Execution
A plug-in’s second option for impersonation is to specify a user ID when calling the IPluginExecutionContext interface’s CreateCrmService method. This allows the plug-in to determine on the fly which user to impersonate, possibly pulling a value from a registry setting or configuration file.