Skip to content

Instantly share code, notes, and snippets.

@topolik
Last active February 22, 2016 16:22
Show Gist options
  • Save topolik/db15fdf0a09254d5312d to your computer and use it in GitHub Desktop.
Save topolik/db15fdf0a09254d5312d to your computer and use it in GitHub Desktop.
This script grants all available permissions to Batman role
import com.liferay.portal.kernel.model.*;
import com.liferay.portal.kernel.service.*;
import com.liferay.portal.kernel.security.permission.*;
import com.liferay.portal.kernel.util.*;
long companyId = PortalUtil.getDefaultCompanyId();
Role batman = RoleLocalServiceUtil.getRole(companyId, "Batman");
List<String> models = ResourceActionsUtil.getModelNames();
for(Portlet portlet : PortletLocalServiceUtil.getPortlets()) {
models.add(portlet.getPortletId());
}
models = new ArrayList(new TreeSet(models));
for(String model : models) {
List<String> actions = ResourceActionsUtil.getModelResourceActions(model);
if (actions.size() == 0) {
actions = ResourceActionsUtil.getPortletResourceActions(model);
}
ResourcePermissionLocalServiceUtil.setResourcePermissions(
companyId, model, ResourceConstants.SCOPE_COMPANY,
String.valueOf(companyId), batman.getRoleId(),
actions.toArray(new String[0]));
out.println(model + ": " + new ArrayList(actions));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment