POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

Impersonating a Dynamics CRM user is fairly straightforward in server-side code and using SDK. We have covered it before in the blog post How to Impersonate in Microsoft Dynamics CRM.

development

But how can we do this in client-side code, specifically Silverlight?

The first obvious approach would be not to use the context to obtain service, but to create your own, and define the username/password for another user in the code. This is widely used in Dynamics CRM portals and many server-side implementations, but we try to avoid this method in client-side applications such as Silverlight.

For that reason, the approach we would use in this case is impersonating the CallerId in the SOAP header of the call. We do not need to know anyone’s password or even username, just their CRM GUID:

In one implementation of this code, we needed this to have a custom audit of the user’s actions in the Silverlight component. If we’re going to do this, we want any user action to happen with the user’s own context and credentials, so that CRM security is used for the calls and so that we can get the correct “modified by” data. However, we don’t want to give the user any unnecessary permissions to the audit entity, or else a malicious user could tamper with the auditing.

So let’s run a few tests:

A user with absolutely no permissions for the entity will fail to impersonate:

impersonating a Dynamics CRM user - no permissions

A user will need at least the minimum read/create permission for the entity before the delegation can work:

impersonating a Dynamics CRM user - some permissions

The created records will be created by and owned by a service user, and “Created By (Delegate)” will be our actual user:

Note that while users have basic permission to the entity, they cannot see any of the created records because they are owned by the service user.

There you go—impersonate away!

If this relevant to your interests, you might also be interested in our Dear Joe CRM post on the differences between JavaScript, Silverlight and Plug-ins for Dynamics CRM.

Happy CRM’ing!

Avatar for JoeCRM

JoeCRM

Joe CRM is a CRM superhero who runs on pure Microsoft Dynamics CRM adrenaline. As the face of PowerObjects, Joe CRM’s mission is to reveal innovative ways to use Dynamics CRM and bring the application to more businesses and organizations around the world.