RE: How to check resource permission for impersonating a user ?

Vishnu S Kumar, modified 6 Years ago. Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts
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;
      }

    }
Vishnu S Kumar, modified 6 Years ago. Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts
found  a solution
 ResourcePermissionLocalServiceUtil.hasResourcePermission(
          themeDisplay.getCompany().getCompanyId(), User.class.getName(),
          ResourceConstants.SCOPE_INDIVIDUAL,
          String.valueOf(UserLocalServiceUtil.getUser(impUserId).getPrimaryKey()), role.getRoleId(),
          ActionKeys.IMPERSONATE);