Skip to content

Instantly share code, notes, and snippets.

@nshaw
Created February 8, 2013 19:06
Show Gist options
  • Save nshaw/4741190 to your computer and use it in GitHub Desktop.
Save nshaw/4741190 to your computer and use it in GitHub Desktop.
import com.liferay.portal.model.Organization
import com.liferay.portal.model.Role
import com.liferay.portal.model.User
import com.liferay.portal.security.permission.PermissionChecker
import com.liferay.portal.security.permission.PermissionCheckerBag
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil
import com.liferay.portal.service.OrganizationLocalServiceUtil
import com.liferay.portal.service.RoleLocalServiceUtil
import com.liferay.portal.service.UserLocalServiceUtil
import com.liferay.portal.service.permission.PortletPermissionUtil
User user = UserLocalServiceUtil.getUserById(5343860);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
Organization organization = OrganizationLocalServiceUtil.getOrganization(1270060);
boolean hasPermission = PortletPermissionUtil.contains(
permissionChecker, organization.getGroupId(), null,
"custompermissions_WAR_custompermissionsportlet",
"ADD_AS_CUSTOM_ADMIN");
System.out.println(hasPermission);
System.out.println("Full data:");
System.out.println("Organization groupId: " + organization.getGroupId());
List<Role> userOrgRoles = RoleLocalServiceUtil.getUserGroupRoles(user.getUserId(), organization.getGroupId());
for (Role curRole : userOrgRoles) {
System.out.println("User org roles: " + curRole.getName());
}
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
for (Role curRole : userRoles) {
System.out.println("User portal roles: " + curRole.getName());
}
PermissionCheckerBag userBag = permissionChecker.getUserBag(user.getUserId(), organization.getGroupId());
List<Role> groupRoles = userBag.getRoles();
for (Role curRole : groupRoles) {
System.out.println("User group roles: " + curRole.getName());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment