List of usage examples for com.liferay.portal.kernel.security.membershippolicy RoleMembershipPolicyUtil isRoleRequired
public static boolean isRoleRequired(long userId, long roleId) throws PortalException
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java
License:Open Source License
public long[] checkRoles(long userId, long[] roleIds) throws PortalException { long[] oldRoleIds = null; PermissionChecker permissionChecker = getPermissionChecker(); if (userId != CompanyConstants.SYSTEM) { // Add back any mandatory roles or roles that the administrator does // not have the rights to remove and check that he has the // permission to add a new role List<Role> oldRoles = RoleLocalServiceUtil.getUserRoles(userId); oldRoleIds = new long[oldRoles.size()]; for (int i = 0; i < oldRoles.size(); i++) { Role role = oldRoles.get(i); if (!ArrayUtil.contains(roleIds, role.getRoleId()) && (!RolePermissionUtil .contains(permissionChecker, role.getRoleId(), ActionKeys.ASSIGN_MEMBERS) || RoleMembershipPolicyUtil.isRoleRequired(userId, role.getRoleId()))) { roleIds = ArrayUtil.append(roleIds, role.getRoleId()); }//from ww w . ja v a2 s.c om oldRoleIds[i] = role.getRoleId(); } } // Check that the administrator has the permission to add a new role and // that the role membership is allowed for (long roleId : roleIds) { if ((oldRoleIds != null) && ArrayUtil.contains(oldRoleIds, roleId)) { continue; } RolePermissionUtil.check(permissionChecker, roleId, ActionKeys.ASSIGN_MEMBERS); } if (userId != CompanyConstants.SYSTEM) { return UsersAdminUtil.addRequiredRoles(userId, roleIds); } return roleIds; }