Prasad
Prasad

Reputation: 686

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?

Upvotes: 1

Views: 808

Answers (1)

Pankaj Kathiriya
Pankaj Kathiriya

Reputation: 4210

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

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

Upvotes: 1

Related Questions