Search code examples
liferayhookliferay-6liferay-themeliferay-aui

How to assign a Site Role for user in Liferay


I am creating the users programatically and trying to assign the site role programatically. I need to assign the "Site Administration" role for a user. So I tried as follows,

 Role role = RoleLocalServiceUtil.getRole(companyId, "Site Administrator");
   System.out.println("Role Id is !! " + role.getRoleId());
   UserLocalServiceUtil.addRoleUser(role.getRoleId(), newUser.getUserId());
   UserLocalServiceUtil.updateUser(newUser);

From the above code, The "Site Administration" role is assigned as a "Regular Role". I need the "Site Administration" role is assigned as a "Site Role".

Any suggestion how can I assign the role as a Site Role?


Solution

  • You have to use UserGroupRoleLocalServiceUtil.java's API method as below.

    public static void addUserGroupRoles(long userId, long groupId,
            long[] roleIds)