Example usage for com.liferay.portal.kernel.security.permission ActionKeys ADD_ORGANIZATION

List of usage examples for com.liferay.portal.kernel.security.permission ActionKeys ADD_ORGANIZATION

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.permission ActionKeys ADD_ORGANIZATION.

Prototype

String ADD_ORGANIZATION

To view the source code for com.liferay.portal.kernel.security.permission ActionKeys ADD_ORGANIZATION.

Click Source Link

Usage

From source file:com.liferay.users.admin.web.internal.portlet.MyOrganizationsPortlet.java

License:Open Source License

@Override
protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

    String path = getPath(renderRequest, renderResponse);

    if (path.equals("/edit_organization.jsp")) {
        try {//  w ww  . j  av  a2s.  c o m
            long organizationId = ParamUtil.getLong(renderRequest, "organizationId");

            if (organizationId == 0) {
                PortalPermissionUtil.check(PermissionThreadLocal.getPermissionChecker(),
                        ActionKeys.ADD_ORGANIZATION);
            }
        } catch (PrincipalException pe) {
            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }

            SessionErrors.add(renderRequest, pe.getClass());

            path = "/error.jsp";
        }

        include(path, renderRequest, renderResponse);
    } else {
        super.doDispatch(renderRequest, renderResponse);
    }
}

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

License:Open Source License

@Override
public Organization createOrganization(String name, String type, long regionId, long countryId, long statusId,
        String comment, boolean site, long[] addresses, long[] emailAddresses, long[] phones, long[] websites,
        long[] orgLabors) throws PortalException {

    _log.info("Creating organization ... ");

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

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION);

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

    User creator = this.getGuestOrUser();

    ServiceContext serviceContext = new ServiceContext();

    Organization organization = OrganizationLocalServiceUtil.addOrganization(creator.getUserId(),
            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, name, type, regionId, countryId, statusId,
            comment, site, serviceContext);

    _log.debug("        ... organization ...");

    this.updateOrganizationParts(organization, addresses, emailAddresses, phones, websites, orgLabors);

    return organization;
}

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

License:Open Source License

protected void checkUpdateUserPermission(long updateUserId, long userId, long companyId, long[] groupIds,
        long[] organizationIds, long[] roleIds, long[] userGroupIds, ServiceContext serviceContext)
        throws PortalException {

    Company company = CompanyLocalServiceUtil.getCompany(companyId);

    // Adding user must be member of everything he adds

    long[] userIds = new long[] { updateUserId };

    // Check if creator / updater is also part in the groups
    ServicePermissionUtil.checkMembership(userIds, groupIds, organizationIds, roleIds, userGroupIds);

    if (groupIds != null && groupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER);
        angularGroupService.checkGroups(userId, groupIds);
    }//ww  w . j a  v  a2 s. c  o  m

    if (organizationIds != null && organizationIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION);
        angularOrganizationService.checkOrganizations(userId, organizationIds);
    }

    if (roleIds != null && roleIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);
        angularRoleService.checkRoles(userId, roleIds);
    }

    if (userGroupIds != null && userGroupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
        angularUserGroupService.checkUserGroupIds(userId, userGroupIds);
    }

    if (serviceContext == null) {
        serviceContext = new ServiceContext();
    }

    boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser");

    long defaultUserId = userLocalService.getDefaultUserId(companyId);

    if (((updateUserId != 0) && (updateUserId != defaultUserId))
            || (!company.isStrangers() && !anonymousUser)) {

        UserPermissionUtil.check(getPermissionChecker(), updateUserId, ActionKeys.UPDATE_USER);

        UserPermissionUtil.check(getPermissionChecker(), userId, organizationIds, ActionKeys.UPDATE);
    }
}

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

License:Open Source License

protected void checkAddUserPermission(long creatorUserId, long companyId, String emailAddress, long[] groupIds,
        long[] organizationIds, long[] roleIds, long[] userGroupIds, ServiceContext serviceContext)
        throws PortalException {

    Company company = CompanyLocalServiceUtil.getCompany(companyId);

    // Check if user has an according right assigned with add user permission; Either he owns the right itself, by his roles or by his user roles
    User creator = this.getGuestOrUser();

    long[] userIds = new long[] { creatorUserId };

    // Adding user must be member of everything he adds
    ServicePermissionUtil.checkMembership(userIds, groupIds, organizationIds, roleIds, userGroupIds);

    if (groupIds != null && groupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_TO_PAGE);
        angularGroupService.checkGroups(0, groupIds);
    }/* ww  w  .  jav  a 2 s . co m*/

    if (organizationIds != null && organizationIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION);
        angularOrganizationService.checkOrganizations(0, organizationIds);
    }

    if (roleIds != null && roleIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);
        angularRoleService.checkRoles(0, roleIds);
    }

    if (userGroupIds != null && userGroupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
        angularUserGroupService.checkUserGroupIds(0, userGroupIds);
    }

    boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser");

    long defaultUserId = userLocalService.getDefaultUserId(companyId);

    if (((creatorUserId != 0) && (creatorUserId != defaultUserId))
            || (!company.isStrangers() && !anonymousUser)) {
        ServicePermissionUtil.checkAllPersonalPermissions(creator, ActionKeys.ADD_USER, companyId,
                getPermissionChecker(), User.class.getName());
    }

    if ((creatorUserId == 0) || (creatorUserId == defaultUserId)) {
        if (!company.isStrangersWithMx() && company.hasCompanyMx(emailAddress)) {

            throw new UserEmailAddressException.MustNotUseCompanyMx(emailAddress);
        }
    }
}