Skip to content

Instantly share code, notes, and snippets.

@cmaggiulli
Created May 4, 2017 06:36
Show Gist options
  • Save cmaggiulli/b83179d74b484844e281e9d68c3a3242 to your computer and use it in GitHub Desktop.
Save cmaggiulli/b83179d74b484844e281e9d68c3a3242 to your computer and use it in GitHub Desktop.
Impersonate User script to run in Liferay 6.2 Script Console
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.util.Encryptor;
import javax.servlet.http.HttpServletRequest;
String key = "23410447";
String uid = "";
ThemeDisplay themeDisplay = null;
HttpServletRequest request = null;
try {
request = PortalUtil.getHttpServletRequest(actionRequest);
themeDisplay = (ThemeDisplay) request.getAttribute("themeDisplay");
uid = Encryptor.encrypt(PortalUtil.getCompany(request).getKeyObj(), key);
themeDisplay.setDoAsUserId(uid);
} catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment