I finally solved this. It was, indeed, using the function setResourcePermission. Just for helping the people around here, I´ll explain the arguments briefly, in order:
- long companyId: the id of the portal instance.
- String name: the resource´s name, in this case, "com.liferay.portal.model.Role".
- int scope: it has to be with the joint the permission affects. 1 is the entire instance of the portal while 4 is the only role referenced in the...
- String primKey: is the Id of the role that will be able to be "manipulated" by...
- long roleId: the id of the Role that will have the permissions over the role referenced in the previous argument.
- String[] actionIds: an array of keys determining the actions. They are KEYS, not Ids,. E.g. VIEW, ASSIGN_MEMBERS...
So, for instance, a call like this:
PermissionResourceLocalServiceUtil.setResourcePermissions(10000,"com.liferay.portal.model.Role",4,"20150",22000, {"VIEW", "ASSIGN_MEMBERS"});
Will grant permissions to the role 22000 of View and a assignation of users to the role "20150" in the portal instance whose id is 10000.
Edit: another version of the same function is setOwnerResourcePermissions, which is the same but gives you the possibility to specify the ownerId of the permission.