Example usage for com.liferay.portal.kernel.model RoleConstants TYPE_ORGANIZATION

List of usage examples for com.liferay.portal.kernel.model RoleConstants TYPE_ORGANIZATION

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model RoleConstants TYPE_ORGANIZATION.

Prototype

int TYPE_ORGANIZATION

To view the source code for com.liferay.portal.kernel.model RoleConstants TYPE_ORGANIZATION.

Click Source Link

Usage

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long roleId = ParamUtil.getLong(actionRequest, "roleId");

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }/* w  w w.  j a v  a 2  s  .c o m*/

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources = StringUtil
            .split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources = StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
        resourceActionsMap.put(portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
        resourceActionsMap.put(relatedPortletResource,
                ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
        resourceActionsMap.put(modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

        String selResource = entry.getKey();
        List<String> actions = entry.getValue();

        actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

        for (String actionId : actions) {
            String target = selResource + actionId;

            boolean selected = ArrayUtil.contains(selectedTargets, target);

            if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

                continue;
            }

            String[] groupIds = StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

            groupIds = ArrayUtil.distinct(groupIds);

            int scope = ResourceConstants.SCOPE_COMPANY;

            if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
                    || (role.getType() == RoleConstants.TYPE_PROVIDER)
                    || (role.getType() == RoleConstants.TYPE_SITE)) {

                scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
            } else {
                if (groupIds.length > 0) {
                    scope = ResourceConstants.SCOPE_GROUP;
                }
            }

            updateAction(role, themeDisplay.getScopeGroupId(), selResource, actionId, selected, scope,
                    groupIds);

            if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

                updateViewControlPanelPermission(role, themeDisplay.getScopeGroupId(), selResource, scope,
                        groupIds);

                rootResourceScope = scope;
                rootResourceGroupIds = groupIds;
            }
        }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
        updateViewRootResourcePermission(role, themeDisplay.getScopeGroupId(), portletResource,
                rootResourceScope, rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

    String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}

From source file:com.liferay.users.admin.web.internal.display.context.UserDisplayContext.java

License:Open Source License

private boolean _isOrganizationRole(UserGroupRole userGroupRole) {
    long roleId = userGroupRole.getRoleId();

    Role role = RoleLocalServiceUtil.fetchRole(roleId);

    if ((role != null) && (role.getType() == RoleConstants.TYPE_ORGANIZATION)) {

        return true;
    }/* w ww .ja v a2 s .com*/

    return false;
}

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

License:Open Source License

@Override
public List<Role> getOrganizationRoles(long companyId) {
    List<Role> allRoles = null;
    try {//from  w  w w.  ja  v  a  2s  .c o m
        allRoles = this.getRolesInCompany(companyId);
    } catch (PortalException e) {
        e.printStackTrace();
    }
    return this.getRolesForSpecificType(allRoles, RoleConstants.TYPE_ORGANIZATION);
}

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

License:Open Source License

public List<UserGroupRole> checkUserGroupRoles(long userId, List<UserGroupRole> userGroupRoles)
        throws PortalException {

    List<UserGroupRole> oldUserGroupRoles = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any user group roles that the administrator does not
        // have the rights to remove or that have a mandatory membership
        User user = UserLocalServiceUtil.getUser(userId);
        List<UserGroup> userGroups = user.getUserGroups();

        for (UserGroup userGroup : userGroups) {
            List<UserGroupRole> roles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId,
                    userGroup.getUserGroupId());
            oldUserGroupRoles.addAll(roles);
        }/*from   w  w  w  .j a va2s  . c  o  m*/

        for (UserGroupRole oldUserGroupRole : oldUserGroupRoles) {
            Role role = oldUserGroupRole.getRole();
            Group group = oldUserGroupRole.getGroup();

            if (userGroupRoles.contains(oldUserGroupRole)) {
                continue;
            }

            if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
                Organization organization = OrganizationLocalServiceUtil
                        .getOrganization(group.getOrganizationId());

                if (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                        || OrganizationMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                organization.getOrganizationId(), role.getRoleId())
                        || OrganizationMembershipPolicyUtil.isRoleRequired(userId,
                                organization.getOrganizationId(), role.getRoleId())) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            } else if (role.getType() == RoleConstants.TYPE_SITE) {
                if (!userGroupRoles.contains(oldUserGroupRole)
                        && (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                                || SiteMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                        group.getGroupId(), role.getRoleId())
                                || SiteMembershipPolicyUtil.isRoleRequired(userId, group.getGroupId(),
                                        role.getRoleId()))) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            }
        }
    }

    // Check that the administrator has the permission to add a new user
    // group role and that the user group role membership is allowed

    for (UserGroupRole userGroupRole : userGroupRoles) {
        if ((oldUserGroupRoles == null) || !oldUserGroupRoles.contains(userGroupRole)) {

            UserGroupRolePermissionUtil.check(permissionChecker, userGroupRole.getGroupId(),
                    userGroupRole.getRoleId());
        }
    }

    return userGroupRoles;
}

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

License:Open Source License

@Override
public User updateUser(long userId, String oldPassword, String newPassword1, String newPassword2,
        boolean passwordReset, String reminderQueryQuestion, String reminderQueryAnswer, String screenName,
        String emailAddress, long facebookId, String openId, boolean portrait, byte[] portraitBytes,
        String languageId, String timeZoneId, String greeting, String comments, String firstName,
        String middleName, String lastName, long prefixId, long suffixId, boolean male, int birthdayMonth,
        int birthdayDay, int birthdayYear, String smsSn, String facebookSn, String jabberSn, String skypeSn,
        String twitterSn, String jobTitle, long[] groupIds, long[] organizationIds, long[] roleIds,
        List<UserGroupRole> userGroupRoles, long[] userGroupIds, List<Address> addresses,
        List<EmailAddress> emailAddresses, List<Phone> phones, List<Website> websites,
        List<AnnouncementsDelivery> announcementsDelivers, ServiceContext serviceContext)
        throws PortalException {

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

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

    PortalPermissionUtil.check(getPermissionChecker(), AngularActionKeys.UPDATE_USER);

    _log.debug("    ... processing ... ");

    long creatorId = 0;

    try {/* www.j av a  2  s .  c  o  m*/
        creatorId = this.getUserId();
    } catch (PrincipalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to get current user ID", pe);
        }
    }

    if (StringUtils.isEmpty(emailAddress)) {
        throw new PortalException("A email address is needed for new users!");
    }

    // Null safe actions
    if (groupIds == null) {
        groupIds = new long[0];
    }

    if (organizationIds == null) {
        organizationIds = new long[0];
    }

    if (roleIds == null) {
        roleIds = new long[0];
    }

    if (userGroupRoles == null) {
        userGroupRoles = new ArrayList<UserGroupRole>();
    }

    if (userGroupIds == null) {
        userGroupIds = new long[0];
    }

    if (addresses == null) {
        addresses = new ArrayList<Address>();
    }

    if (emailAddresses == null) {
        emailAddresses = new ArrayList<EmailAddress>();
    }

    if (phones == null) {
        phones = new ArrayList<Phone>();
    }

    if (websites == null) {
        websites = new ArrayList<Website>();
    }

    if (announcementsDelivers == null) {
        announcementsDelivers = new ArrayList<AnnouncementsDelivery>();
    }

    User userToUpdate = UserLocalServiceUtil.getUserById(userId);

    if (StringUtils.isEmpty(screenName)) {
        screenName = userToUpdate.getScreenName();
    }

    this.checkUpdateUserPermission(creatorId, userId, userToUpdate.getCompanyId(), groupIds, organizationIds,
            roleIds, userGroupIds, serviceContext);

    // Update contact parts
    this.updateUserAddresses(userToUpdate.getContactId(), addresses);
    this.updateUserEmailAddress(userToUpdate.getContactId(), emailAddresses);
    this.updateUserPhones(userToUpdate.getContactId(), phones);
    this.updateUsrWebsites(userToUpdate.getContactId(), websites);
    this.updateAnnouncementsDeliveries(userToUpdate.getContactId(), announcementsDelivers);

    if (creatorId == userId) {
        emailAddress = StringUtil.toLowerCase(emailAddress.trim());

        if (!StringUtil.equalsIgnoreCase(emailAddress, userToUpdate.getEmailAddress())) {

            validateEmail(emailAddress, userToUpdate);
        }
    }

    validateUpdatePermission(userToUpdate, screenName, emailAddress, firstName, middleName, lastName, prefixId,
            suffixId, birthdayMonth, birthdayDay, birthdayYear, male, jobTitle);

    // Group membership policy

    long[] oldGroupIds = userToUpdate.getGroupIds();

    List<Long> addGroupIds = new ArrayList<>();
    List<Long> removeGroupIds = Collections.emptyList();

    if (groupIds != null) {
        removeGroupIds = ListUtil.toList(oldGroupIds);

        groupIds = angularGroupService.checkGroups(userId, groupIds);

        for (long groupId : groupIds) {
            if (ArrayUtil.contains(oldGroupIds, groupId)) {
                removeGroupIds.remove(groupId);
            } else {
                addGroupIds.add(groupId);
            }
        }

        if (!addGroupIds.isEmpty() || !removeGroupIds.isEmpty()) {
            SiteMembershipPolicyUtil.checkMembership(new long[] { userId }, ArrayUtil.toLongArray(addGroupIds),
                    ArrayUtil.toLongArray(removeGroupIds));
        }
    }

    // Organization membership policy

    long[] oldOrganizationIds = userToUpdate.getOrganizationIds();

    List<Long> addOrganizationIds = new ArrayList<>();
    List<Long> removeOrganizationIds = Collections.emptyList();

    if (organizationIds != null) {
        removeOrganizationIds = ListUtil.toList(oldOrganizationIds);

        organizationIds = angularOrganizationService.checkOrganizations(userId, organizationIds);

        for (long organizationId : organizationIds) {
            if (ArrayUtil.contains(oldOrganizationIds, organizationId)) {
                removeOrganizationIds.remove(organizationId);
            } else {
                addOrganizationIds.add(organizationId);
            }
        }

        if (!addOrganizationIds.isEmpty() || !removeOrganizationIds.isEmpty()) {

            OrganizationMembershipPolicyUtil.checkMembership(new long[] { userId },
                    ArrayUtil.toLongArray(addOrganizationIds), ArrayUtil.toLongArray(removeOrganizationIds));
        }
    }

    // Role membership policy

    long[] oldRoleIds = userToUpdate.getRoleIds();

    List<Long> addRoleIds = new ArrayList<>();
    List<Long> removeRoleIds = Collections.emptyList();

    if (roleIds != null) {
        removeRoleIds = ListUtil.toList(oldRoleIds);

        roleIds = angularRoleService.checkRoles(userId, roleIds);

        for (long roleId : roleIds) {
            if (ArrayUtil.contains(oldRoleIds, roleId)) {
                removeRoleIds.remove(roleId);
            } else {
                addRoleIds.add(roleId);
            }
        }

        if (!addRoleIds.isEmpty() || !removeRoleIds.isEmpty()) {
            RoleMembershipPolicyUtil.checkRoles(new long[] { userId }, ArrayUtil.toLongArray(addRoleIds),
                    ArrayUtil.toLongArray(removeRoleIds));
        }
    }

    List<UserGroupRole> oldOrganizationUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> oldSiteUserGroupRoles = new ArrayList<>();

    List<UserGroupRole> oldUserGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);

    for (UserGroupRole oldUserGroupRole : oldUserGroupRoles) {
        Role role = oldUserGroupRole.getRole();

        if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
            oldOrganizationUserGroupRoles.add(oldUserGroupRole);
        } else if (role.getType() == RoleConstants.TYPE_SITE) {
            oldSiteUserGroupRoles.add(oldUserGroupRole);
        }
    }

    List<UserGroupRole> addOrganizationUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> removeOrganizationUserGroupRoles = Collections.emptyList();
    List<UserGroupRole> addSiteUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> removeSiteUserGroupRoles = Collections.emptyList();

    if (userGroupRoles != null) {
        userGroupRoles = angularRoleService.checkUserGroupRoles(userId, userGroupRoles);

        removeOrganizationUserGroupRoles = ListUtil.copy(oldOrganizationUserGroupRoles);
        removeSiteUserGroupRoles = ListUtil.copy(oldSiteUserGroupRoles);

        for (UserGroupRole userGroupRole : userGroupRoles) {
            Role role = userGroupRole.getRole();

            if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
                if (oldOrganizationUserGroupRoles.contains(userGroupRole)) {
                    removeOrganizationUserGroupRoles.remove(userGroupRole);
                } else {
                    addOrganizationUserGroupRoles.add(userGroupRole);
                }
            } else if (role.getType() == RoleConstants.TYPE_SITE) {
                if (oldSiteUserGroupRoles.contains(userGroupRole)) {
                    removeSiteUserGroupRoles.remove(userGroupRole);
                } else {
                    addSiteUserGroupRoles.add(userGroupRole);
                }
            }
        }

        if (!addOrganizationUserGroupRoles.isEmpty() || !removeOrganizationUserGroupRoles.isEmpty()) {

            OrganizationMembershipPolicyUtil.checkRoles(addOrganizationUserGroupRoles,
                    removeOrganizationUserGroupRoles);
        }

        if (!addSiteUserGroupRoles.isEmpty() || !removeSiteUserGroupRoles.isEmpty()) {

            SiteMembershipPolicyUtil.checkRoles(addSiteUserGroupRoles, removeSiteUserGroupRoles);
        }
    }

    // User group membership policy

    long[] oldUserGroupIds = userToUpdate.getUserGroupIds();

    List<Long> addUserGroupIds = new ArrayList<>();
    List<Long> removeUserGroupIds = Collections.emptyList();

    if (userGroupIds != null) {
        removeUserGroupIds = ListUtil.toList(oldUserGroupIds);

        userGroupIds = angularUserGroupService.checkUserGroupIds(userId, userGroupIds);

        for (long userGroupId : userGroupIds) {
            if (ArrayUtil.contains(oldUserGroupIds, userGroupId)) {
                removeUserGroupIds.remove(userGroupId);
            } else {
                addUserGroupIds.add(userGroupId);
            }
        }

        if (!addUserGroupIds.isEmpty() || !removeUserGroupIds.isEmpty()) {
            UserGroupMembershipPolicyUtil.checkMembership(new long[] { userId },
                    ArrayUtil.toLongArray(addUserGroupIds), ArrayUtil.toLongArray(removeUserGroupIds));
        }
    }

    userToUpdate = userLocalService.updateUser(userId, oldPassword, newPassword1, newPassword2, passwordReset,
            reminderQueryQuestion, reminderQueryAnswer, screenName, emailAddress, facebookId, openId, portrait,
            portraitBytes, languageId, timeZoneId, greeting, comments, firstName, middleName, lastName,
            prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, smsSn, facebookSn, jabberSn,
            skypeSn, twitterSn, jobTitle, groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds,
            serviceContext);

    if (!addGroupIds.isEmpty() || !removeGroupIds.isEmpty()) {
        SiteMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addGroupIds), ArrayUtil.toLongArray(removeGroupIds));
    }

    if (!addOrganizationIds.isEmpty() || !removeOrganizationIds.isEmpty()) {
        OrganizationMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addOrganizationIds), ArrayUtil.toLongArray(removeOrganizationIds));
    }

    if (!addRoleIds.isEmpty() || !removeRoleIds.isEmpty()) {
        RoleMembershipPolicyUtil.propagateRoles(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addRoleIds), ArrayUtil.toLongArray(removeRoleIds));
    }

    if (!addSiteUserGroupRoles.isEmpty() || !removeSiteUserGroupRoles.isEmpty()) {

        SiteMembershipPolicyUtil.propagateRoles(addSiteUserGroupRoles, removeSiteUserGroupRoles);
    }

    if (!addOrganizationUserGroupRoles.isEmpty() || !removeOrganizationUserGroupRoles.isEmpty()) {

        OrganizationMembershipPolicyUtil.propagateRoles(addOrganizationUserGroupRoles,
                removeOrganizationUserGroupRoles);
    }

    if (!addUserGroupIds.isEmpty() || !removeUserGroupIds.isEmpty()) {
        UserGroupMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addUserGroupIds), ArrayUtil.toLongArray(removeUserGroupIds));
    }

    return userToUpdate;
}

From source file:jorgediazest.indexchecker.model.IndexCheckerModelQuery.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void addRolesFieldsToData(Map<Long, Data> roleMap, String className, Data data,
        String permissionsField) throws PortalException {

    Object aux = data.get(permissionsField);

    Set<List<Object>> resourcePermissions = null;

    if (aux instanceof List) {
        resourcePermissions = new HashSet<List<Object>>();
        resourcePermissions.add((List<Object>) aux);
    } else if (aux instanceof Set) {
        resourcePermissions = (Set<List<Object>>) aux;
    }//from  www . jav a  2  s . c o  m

    if (resourcePermissions == null) {
        return;
    }

    Set<String> roleIds = new HashSet<String>();
    Set<String> groupRoleIds = new HashSet<String>();

    for (List<Object> resourcePermission : resourcePermissions) {
        long roleId = (Long) resourcePermission.get(0);
        long actionIds = (Long) resourcePermission.get(1);

        if (resourcePermission.size() > 2) {
            int scope = (Integer) resourcePermission.get(2);

            if (scope != ResourceConstants.SCOPE_INDIVIDUAL) {
                continue;
            }
        }

        if (hasActionId(actionIds, className, ActionKeys.VIEW)) {
            Data role = roleMap.get(roleId);

            if (role == null) {
                continue;
            }

            long groupId = data.get("permissionsGroupId", 0L);

            int type = role.get("type", -1);

            if ((type == RoleConstants.TYPE_ORGANIZATION) || (type == RoleConstants.TYPE_SITE)) {

                groupRoleIds.add(groupId + StringPool.DASH + roleId);
            } else {
                roleIds.add(Long.toString(roleId));
            }
        }
    }

    data.set("roleId", roleIds);
    data.set("groupRoleId", groupRoleIds);
}