Example usage for com.liferay.portal.kernel.service.permission RolePermissionUtil check

List of usage examples for com.liferay.portal.kernel.service.permission RolePermissionUtil check

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service.permission RolePermissionUtil check.

Prototype

public static void check(PermissionChecker permissionChecker, long roleId, String actionId)
            throws PrincipalException 

Source Link

Usage

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java

License:Open Source License

@Override
public Role updateRole(long roleId, String name, int type, String className, Map<Locale, String> titleMap,
        Map<Locale, String> descriptionMap, String subType) throws PortalException {

    _log.info("Updating role ... ");

    _log.debug("    security check ... ");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.UPDATE);
    RolePermissionUtil.check(getPermissionChecker(), roleId, ActionKeys.UPDATE);

    _log.debug("    writing information ... ");

    return RoleLocalServiceUtil.updateRole(roleId, name, titleMap, descriptionMap, subType, null);
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java

License:Open Source License

@Override
public Role deleteRole(long roleId) throws PortalException {

    _log.info("Deleting role with id: " + String.valueOf(roleId));

    _log.debug("    security check ...");

    RolePermissionUtil.check(getPermissionChecker(), roleId, ActionKeys.DELETE);

    _log.debug("    deleting role ...");

    return RoleLocalServiceUtil.deleteRole(roleId);
}

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 w  ww  .  j a  v  a  2  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;
}