Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to check resource permission for impersonating a user ?
I would like to test whether the logged in user has the permission to impresonate another user. I did the following permission check but it didn't work even though the logged in user has the role which has permission to impersonate another user.
Long impUserId = ParamUtil.getLong(actionRequest, "impUserId");
for (Role role : UserLocalServiceUtil.getUser(themeDisplay.getRealUserId()).getRoles()) {
auth = ResourcePermissionLocalServiceUtil.hasResourcePermission(
themeDisplay.getCompany().getPrimaryKey(), User.class.getName(), groupId,
String.valueOf(UserLocalServiceUtil.getUser(impUserId).getPrimaryKey()),
role.getPrimaryKey(), ActionKeys.IMPERSONATE);
if (auth) {
break;
}
}
found a solution
ResourcePermissionLocalServiceUtil.hasResourcePermission(
themeDisplay.getCompany().getCompanyId(), User.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(UserLocalServiceUtil.getUser(impUserId).getPrimaryKey()), role.getRoleId(),
ActionKeys.IMPERSONATE);
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™