3

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.

Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
Marius Popa
  • 564
  • 1
  • 5
  • 22

2 Answers2

1

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.

Marius Popa
  • 564
  • 1
  • 5
  • 22
0

There is a Sitecore.Security.Accounts.UserSwitcher class. I'm not sure if it would do the trick, but you can try:

Sitecore.Security.Accounts.UserSwitcher.Enter(someOtherUser)

and then

Sitecore.Security.Accounts.UserSwitcher.Exit()

or

using (UserSwitcher switcher = new UserSwitcher(...))
{
    ...
}

EDIT:

To check if you are in UserSwitcher mode, use:

User impersonatedUser = UserSwitcher.CurrentValue;

If the value of impersonatedUser is null, it means that you're not in the UserSwitcher mode.

Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
  • In this case, would I be able to check if I am impersonating or not? If so, how? Thanks. – Marius Popa Aug 11 '15 at 08:37
  • @MariusPopa you can use `UserSwitcher.CurrentValue` property. See updated answer. – Marek Musielak Aug 11 '15 at 08:49
  • Cool. I will give it a try and come back with an answer. Thanks. – Marius Popa Aug 11 '15 at 11:36
  • So...apparently the `UserSwitcher` could not be used in this case, because this would mean that I have the possibility to only make some operations on that specific user, but not actually log in with it as normally. So I still have to stick to the virtual user idea. – Marius Popa Sep 04 '15 at 07:29