Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Log In As User View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/21/2012 8:54:03 PM
   
Log In As User
In the CMSDesk there is an option under Administration>Users when you view/edit a user to log in as a user. Is this option only available for Global Administrators or how can I enable it for specific roles? I've spent some time viewing the roles, permissions and UI personalization but havn't found where it's at.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/22/2012 8:17:50 AM
   
RE:Log In As User
Hello.

It is possible, however some simple modification is required.

You can navigate to \CMSModules\Membership\Pages\Users\User_Edit_General.aspx.cs and see code below, which is responsible for this link:

// Display impersonation link if current user is global administrator
if (CMSContext.CurrentUser.IsGlobalAdministrator && RequestHelper.IsFormsAuthentication() && (ui != null) && (ui.UserID != CMSContext.CurrentUser.UserID) && !ui.IsPublic())
{
// Display impersonation link only if both users have disabled access to sitemanager
// or current user has access enabled
if (!CMSContext.CurrentUser.UserSiteManagerDisabled || !ui.UserIsGlobalAdministrator || ui.UserSiteManagerDisabled)
{
string message = GetImpersonalMessage(ui);

// Header actions
string[,] actions = new string[1, 11];

actions[0, 0] = HeaderActions.TYPE_LINKBUTTON;
actions[0, 1] = GetString("Membership.Impersonate");
actions[0, 2] = "if (!confirm('" + message + "')) { return false; }";
actions[0, 4] = GetString("Membership.Impersonate");
actions[0, 5] = GetImageUrl("Objects/CMS_User/Impersonate.png");
actions[0, 6] = "impersonate";
actions[0, 8] = "true";

CurrentMaster.HeaderActions.Actions = actions;
CurrentMaster.HeaderActions.ActionPerformed += new CommandEventHandler(HeaderActions_ActionPerformed);
}
}


If you modify if condition in a proper way, given element can be shown for any user or role.

Best Regards,
Radek Macalik

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/25/2012 8:21:22 PM
   
RE:Log In As User
Worked like a charm, Thanks Radek. I did look around but still haven't quite figured my way around all the files.

User avatar
Member
Member
steve-ecutek - 5/29/2013 8:40:11 AM
   
RE:Log In As User - Code changes don't work for Kentico 7
Hello Radek,

We implemented the changes you describe above, to give 'Log in as user' ability to non-Global Admin users. We did this with version 6 some months ago.

We have now upgraded to version 7.

The code is slightly different in Kentico 7, but we applied the same effective changes to the v7 code, but this no longer works. I think there is some extra check now inside UserImpersonate() method. Here is my reasoning...

From our code mods, we do get the 'Log in as User' button and can click the button.
The line 'currentUser.UserImpersonate(ui);' does run, but has no effect. The user is not impersonated and the page is not redirected;

Adding the line 'currentUser.IsGlobalAdministrator = true;' just before the UserImpersonate() method call causes the action to succeed. Therefore, I think that the UserImpersonate() call is behaving differently in v7 to v6. Inside this call, there must be a check for IsGlobalAdministrator that was not there in v6.

We cannot find anything useful in the logs, and a Google (or Kentico Site) search for UserImpersonate does not bring up any docs or examples.

Can you please confirm this issue and perhaps tell me how to get around the problem?

Best regards

Stephen Done

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/29/2013 8:55:54 AM
   
RE:Log In As User - Code changes don't work for Kentico 7
Stephen I ran into the same problem when I upgraded the client I made this mod for from 6 to 7. The Impersonate option is no longer at the user edit level. You will find the option to impersonate someone at the top right (down arrow by your username if global admin). You will find the code you need to modify now in the CMSAdminControls/UI/Header.ascx control.

User avatar
Member
Member
steve-ecutek - 5/29/2013 9:45:42 AM
   
RE:Log In As User - Code changes don't work for Kentico 7
Hi FroggEye,

Thanks for the reply.

Actually, I think the 'Log in as user' is available from both the User and at the top right down arrow - both when Global Admin of course.

So, thanks to your suggestion, I can now also display the 'down arrow' for non-GlobalAdmin users. However, I still have the same problem where the button click does not actually work unless you set CurrentUser.IsGlobaldmin=true before the call to UserImpersonate.

Is this what you had to do with version 7 too?
Or did you find another fix?

Best regards

Steve

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/29/2013 11:33:52 AM
   
RE:Log In As User - Code changes don't work for Kentico 7
Wow, I never got in depth and tested it that far. All I knew is the button was not available and the users have not reported it not working either.

I found that if you set a few session values you don't need to be an administrator. Check out my simple code:
ui = UserInfoProvider.GetUserInfo(impersonateUserName);
SessionHelper.SetValue("ImpersonateUserName", impersonateUserName);
SessionHelper.SetValue("OriginalUserName", CMSContext.CurrentUser.UserName);
CMSContext.CurrentUser.UserImpersonate(ui, ResolveUrl("~/Home/"));

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/30/2013 11:03:23 AM
   
RE:Log In As User - Code changes don't work for Kentico 7
After a bit of testing yesterday, I need to correct my statement above. You can set the following 2 session values prior to calling UserImpersonate(ui) and should get the results you're expecting
SessionHelper.SetValue("OriginalUserName", CMSContext.CurrentUser.UserName);
SessionHelper.SetValue("OriginalUserNameHash", EncryptionHelper.EncryptData(SecurityHelper.GetSHA2Hash(CMSContext.CurrentUser.GetStringValue("UserPassword", ""))));