Search code examples
sitecorevirtualimpersonationsitecore7

Create virtual user for Sitecore solution - Impersonation purpose


I really need some help, but let me explain first what I have to do.

I have a Sitecore super-user, which has the Impersonation role. This user is supposed to be able to impersonate other users (all of them are on extranet domain), having the profile information and the roles of the original user.

The main thing about this super-user is that he should be able to impersonate another and change settings or other aspects of the impersonated account.

I tried different approaches but I can't seem to be able to figure this out. Creating virtual users is the way I am thinking, but can't succeed.

Just to mention, each User from this solution has a custom Profile template assigned to them that must be kept after creating the virtual user.

Also, I have some quick questions. Does anyone know where are this virtual users located after creation? Or for how much time are these stored? Do they need to be deleted somehow?

Many thanks to anyone that could help.


Solution

  • So,

    Apparently the solution for was using Virtual Users actually, like in the following:

    var virtualUser = AuthenticationManager.BuildVirtualUser(emailAddress, true);
    
    SetBaseProfile();
    SaveUserRoles();
    
    // login the virtual user
    AuthenticationManager.Login(virtualUser);
    

    In order to check if the active user is virtual or not, I had to use:

    AuthenticationManager.GetActiveUser().RuntimeSetting.isVirtual;
    

    Thanks.