Using the User Impersonation Feature in DHIS2¶
Overview¶
User impersonation, also known as user switching, is a powerful feature provided in DHIS2 for administrative users to log in as another user. This feature is especially useful for troubleshooting or resolving user-related issues, as it allows an administrator to experience DHIS2 exactly as the user does.
This feature is built upon the SwitchUserFilter from Spring Security, but with additional configuration options.
Note
The feature is disabled by default. To enable it, you must set the
switch_user_feature.enabledproperty totruein yourdhis.conffile.This feature is considered experimental and is only meant to be called from configured IP address(s). Hence, to use it you must know the IP address from which you will be calling it and configure the
switch_user_allow_listed_ipsproperty in thedhis.conffile. This restriction might be removed in the future.
How It Works¶
The user impersonation feature operates in the following manner:
-
An administrative user makes a request to a specific URL (e.g.,
/impersonate?username=USERNAME) with theusernameparameter indicating the username of the user they wish to impersonate. -
The user impersonation feature intercepts this request, switches the
SecurityContextto the new user, and redirects to the home page. -
While impersonating another user, the administrative user can make requests as if they were the impersonated user.
-
To switch back to the original user, the administrative user makes a request to another URL ( e.g.,
/impersonateExit). The user impersonation feature intercepts this request, switches theSecurityContextback to the original user, and redirects to the home page.
How To Use¶
Follow these steps to use the user impersonation feature:
- Log in as an administrative user with either the
ALLorF_IMPERSONATE_USERauthority. - Navigate to the URL for user impersonation (e.g.,
/impersonate?username=USERNAME). - Provide the
usernameparameter of the user you wish to impersonate. - The system will switch your session to that of the impersonated user, and you will be redirected to the home page.
- Perform any actions necessary for troubleshooting or user support.
- When you're finished, navigate to the URL to end impersonation (e.g.,
/impersonateExit). Your session will be switched back to your original administrative user.
Configuration¶
The user impersonation feature configuration options.
switch_user_feature.enabled(Enable or disable the feature, default:disabled)switch_user_allow_listed_ips(Default allowed IP(s) are;localhost,127.0.0.1,[0:0:0:0:0:0:0:1])
Security restrictions¶
- Feature must be enabled in the
dhis.confconfiguration file, default value is;disabled. - Users trying to impersonate need to send requests from an allowed IP.
- Users without the
ALLauthority can not impersonate another user that has theALLauthority. - Users can not impersonate themselves.
Security Implications¶
This feature should be used with caution due to its inherent security implications. Only trusted administrators should be granted the capability to impersonate users. It's also recommended to pay attention to the log events related to the user impersonation.
User impersonation events are logged in the following format: Authentication event: AuthenticationSwitchUserEvent; username: USER_DOING_THE_IMPERSONATION; targetUser: USER_BEING_IMPERSONATED;