List of usage examples for com.liferay.portal.kernel.security.membershippolicy SiteMembershipPolicyUtil isMembershipProtected
public static boolean isMembershipProtected(PermissionChecker permissionChecker, long userId, long groupId) throws PortalException
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularGroupServiceImpl.java
License:Open Source License
public long[] checkGroups(long userId, long[] groupIds) throws PortalException { long[] oldGroupIds = null; PermissionChecker permissionChecker = getPermissionChecker(); User user = null;//from w w w . j a v a 2 s. com if (userId != CompanyConstants.SYSTEM) { // Add back any mandatory groups or groups that the administrator // does not have the rights to remove and check that he has the // permission to add a new group user = userPersistence.findByPrimaryKey(userId); List<Group> oldGroups = GroupLocalServiceUtil.getUserGroups(userId); oldGroupIds = new long[oldGroups.size()]; for (int i = 0; i < oldGroups.size(); i++) { Group group = oldGroups.get(i); if (!ArrayUtil.contains(groupIds, group.getGroupId()) && (!GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS) || SiteMembershipPolicyUtil.isMembershipProtected(permissionChecker, user.getUserId(), group.getGroupId()) || SiteMembershipPolicyUtil.isMembershipRequired(userId, group.getGroupId()))) { groupIds = ArrayUtil.append(groupIds, group.getGroupId()); } oldGroupIds[i] = group.getGroupId(); } } // Check that the administrator has the permission to add a new group // and that the group membership is allowed for (long groupId : groupIds) { if ((oldGroupIds != null) && ArrayUtil.contains(oldGroupIds, groupId)) { continue; } Group group = GroupLocalServiceUtil.getGroup(groupId); GroupPermissionUtil.check(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS); } return groupIds; }