Example usage for com.liferay.portal.kernel.security.permission PermissionChecker getUserId

List of usage examples for com.liferay.portal.kernel.security.permission PermissionChecker getUserId

Introduction

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

Prototype

public long getUserId();

Source Link

Document

Returns the primary key of the user.

Usage

From source file:com.liferay.alloy.mvc.jsonwebservice.BaseAlloyControllerInvokerImpl.java

License:Open Source License

protected DynamicServletRequest createRequest(String lifecycle, Object... parameters) throws Exception {

    if ((parameters.length % 2) != 0) {
        throw new IllegalArgumentException("Parameters length is not an even number");
    }/* w ww .  jav  a 2 s  .co m*/

    HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(
            new AlloyMockUtil.MockHttpServletRequest());

    DynamicServletRequest request = new DynamicServletRequest(requestWrapper, false);

    for (int i = 0; i < parameters.length; i += 2) {
        request.appendParameter(String.valueOf(parameters[i]), String.valueOf(parameters[i + 1]));
    }

    request.appendParameter("controller", _controller);
    request.appendParameter("format", "json");

    ThemeDisplay themeDisplay = (ThemeDisplay) _themeDisplay.clone();

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    User user = UserLocalServiceUtil.getUser(permissionChecker.getUserId());

    themeDisplay.setUser(user);

    request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);

    request.setAttribute(WebKeys.LAYOUT, themeDisplay.getLayout());

    LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) PortletConfigFactoryUtil.create(_portlet,
            null);

    request.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, liferayPortletConfig);

    request.setAttribute(JavaConstants.JAVAX_PORTLET_PORTLET, _alloyPortlet);

    PortletRequest portletRequest = null;
    PortletResponse portletResponse = null;

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
        portletRequest = createActionRequest();
        portletResponse = createActionResponse();
    } else {
        portletRequest = createRenderRequest();
        portletResponse = createRenderResponse(request, _portlet.getRootPortletId(), themeDisplay.getPlid(),
                lifecycle);
    }

    request.setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, portletRequest);
    request.setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse);

    request.setAttribute(PortletRequest.LIFECYCLE_PHASE, lifecycle);

    request.setAttribute(BaseAlloyControllerImpl.VIEW_PATH, StringPool.BLANK);

    return request;
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public void subscribe(PermissionChecker permissionChecker, long groupId, long plid, String portletId)
        throws PortalException {

    Layout layout = _layoutLocalService.fetchLayout(plid);

    PortletPermissionUtil.check(permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE, false, false);

    _subscriptionLocalService.addSubscription(permissionChecker.getUserId(), groupId,
            com.liferay.portal.kernel.model.PortletPreferences.class.getName(),
            getSubscriptionClassPK(plid, portletId));
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public void unsubscribe(PermissionChecker permissionChecker, long plid, String portletId)
        throws PortalException {

    Layout layout = _layoutLocalService.fetchLayout(plid);

    PortletPermissionUtil.check(permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE, false, false);

    _subscriptionLocalService.deleteSubscription(permissionChecker.getUserId(),
            com.liferay.portal.kernel.model.PortletPreferences.class.getName(),
            getSubscriptionClassPK(plid, portletId));
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static void subscribe(PermissionChecker permissionChecker, long groupId, long plid, String portletId)
        throws PortalException {

    Layout layout = _layoutLocalService.fetchLayout(plid);

    PortletPermissionUtil.check(permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE, false, false);

    _subscriptionLocalService.addSubscription(permissionChecker.getUserId(), groupId,
            com.liferay.portal.kernel.model.PortletPreferences.class.getName(),
            getSubscriptionClassPK(plid, portletId));
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static void unsubscribe(PermissionChecker permissionChecker, long plid, String portletId)
        throws PortalException {

    Layout layout = _layoutLocalService.fetchLayout(plid);

    PortletPermissionUtil.check(permissionChecker, 0, layout, portletId, ActionKeys.SUBSCRIBE, false, false);

    _subscriptionLocalService.deleteSubscription(permissionChecker.getUserId(),
            com.liferay.portal.kernel.model.PortletPreferences.class.getName(),
            getSubscriptionClassPK(plid, portletId));
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

/**
 * @deprecated As of 4.0.0, replaced by {@link
 *             com.liferay.staging.configuration.web.internal.portlet.StagingConfigurationPortlet#editStagingConfiguration(
 *             javax.portlet.ActionRequest, javax.portlet.ActionResponse)}
 *//*from w w w  .j  a  v  a  2s . c  om*/
@Deprecated
@Override
public void updateStaging(PortletRequest portletRequest, Group liveGroup) throws PortalException {

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    long userId = permissionChecker.getUserId();

    if (!GroupPermissionUtil.contains(permissionChecker, liveGroup, ActionKeys.MANAGE_STAGING)) {

        return;
    }

    int stagingType = getStagingType(portletRequest, liveGroup);

    boolean branchingPublic = getBoolean(portletRequest, liveGroup, "branchingPublic");
    boolean branchingPrivate = getBoolean(portletRequest, liveGroup, "branchingPrivate");
    boolean forceDisable = ParamUtil.getBoolean(portletRequest, "forceDisable");

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    serviceContext.setAttribute("forceDisable", forceDisable);

    if (stagingType == StagingConstants.TYPE_NOT_STAGED) {
        if (liveGroup.hasStagingGroup() || liveGroup.isStagedRemotely()) {
            _stagingLocalService.disableStaging(portletRequest, liveGroup, serviceContext);
        }
    } else if (stagingType == StagingConstants.TYPE_LOCAL_STAGING) {
        _stagingLocalService.enableLocalStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                serviceContext);
    } else if (stagingType == StagingConstants.TYPE_REMOTE_STAGING) {
        String remoteAddress = getString(portletRequest, liveGroup, "remoteAddress");

        remoteAddress = stripProtocolFromRemoteAddress(remoteAddress);

        int remotePort = getInteger(portletRequest, liveGroup, "remotePort");
        String remotePathContext = getString(portletRequest, liveGroup, "remotePathContext");
        boolean secureConnection = getBoolean(portletRequest, liveGroup, "secureConnection");
        long remoteGroupId = getLong(portletRequest, liveGroup, "remoteGroupId");

        _stagingLocalService.enableRemoteStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId, serviceContext);
    }
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

protected void checkOmniAdmin() throws PortletException {
    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    if (!permissionChecker.isOmniadmin()) {
        PrincipalException principalException = new PrincipalException.MustBeCompanyAdmin(
                permissionChecker.getUserId());

        throw new PortletException(principalException);
    }/*from  w w  w . j  ava 2  s. c  om*/
}

From source file:com.liferay.message.boards.internal.service.permission.MBCategoryPermission.java

License:Open Source License

private boolean _contains(PermissionChecker permissionChecker, long groupId, long categoryId, String actionId)
        throws PortalException {

    if (_mbBanLocalService.hasBan(groupId, permissionChecker.getUserId())) {
        return false;
    }/*from   www . j a  va  2 s  . co  m*/

    if ((categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
            || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

        return MBPermission.contains(permissionChecker, groupId, actionId);
    }

    MBCategory category = _mbCategoryLocalService.getCategory(categoryId);

    if (actionId.equals(ActionKeys.ADD_CATEGORY)) {
        actionId = ActionKeys.ADD_SUBCATEGORY;
    }

    String portletId = PortletProviderUtil.getPortletId(MBCategory.class.getName(),
            PortletProvider.Action.EDIT);

    Boolean hasPermission = _stagingPermission.hasPermission(permissionChecker, category.getGroupId(),
            MBCategory.class.getName(), category.getCategoryId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }

    if (actionId.equals(ActionKeys.VIEW) && PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {

        try {
            while (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

                category = _mbCategoryLocalService.getCategory(categoryId);

                if (!_hasPermission(permissionChecker, category, actionId)) {

                    return false;
                }

                categoryId = category.getParentCategoryId();
            }
        } catch (NoSuchCategoryException nsce) {
            if (!category.isInTrash()) {
                throw nsce;
            }
        }

        return MBPermission.contains(permissionChecker, category.getGroupId(), actionId);
    }

    return _hasPermission(permissionChecker, category, actionId);
}

From source file:com.liferay.message.boards.internal.service.permission.MBMessagePermission.java

License:Open Source License

private boolean _contains(PermissionChecker permissionChecker, MBMessage message, String actionId)
        throws PortalException {

    if (_mbBanLocalService.hasBan(message.getGroupId(), permissionChecker.getUserId())) {

        return false;
    }/*  www .j  a v  a2  s .  co m*/

    String portletId = PortletProviderUtil.getPortletId(MBMessage.class.getName(), PortletProvider.Action.EDIT);

    Boolean hasPermission = _stagingPermission.hasPermission(permissionChecker, message.getGroupId(),
            MBMessage.class.getName(), message.getMessageId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }

    if (message.isDraft() || message.isScheduled()) {
        if (actionId.equals(ActionKeys.VIEW) && !_contains(permissionChecker, message, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (message.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
                message.getWorkflowClassName(), message.getMessageId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (actionId.equals(ActionKeys.VIEW) && PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {

        long categoryId = message.getCategoryId();

        if ((categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
                || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

            if (!MBPermission.contains(permissionChecker, message.getGroupId(), actionId)) {

                return false;
            }
        } else {
            try {
                MBCategory category = _mbCategoryLocalService.getCategory(categoryId);

                if (!MBCategoryPermission.contains(permissionChecker, category, actionId)) {

                    return false;
                }
            } catch (NoSuchCategoryException nsce) {
                if (!message.isInTrash()) {
                    throw nsce;
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(message.getCompanyId(), MBMessage.class.getName(),
            message.getRootMessageId(), message.getUserId(), actionId)) {

        return true;
    }

    if (!permissionChecker.hasPermission(message.getGroupId(), MBMessage.class.getName(),
            message.getMessageId(), actionId)) {

        return false;
    }

    if (message.isRoot() || !actionId.equals(ActionKeys.VIEW)) {
        return true;
    }

    return _contains(permissionChecker, _mbMessageLocalService.getMessage(message.getParentMessageId()),
            actionId);
}

From source file:com.liferay.message.boards.service.permission.MBDiscussionPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, long companyId, long groupId,
        String className, long classPK, String actionId) {

    if (_mbBanLocalService.hasBan(groupId, permissionChecker.getUserId())) {
        return false;
    }//from w  w  w .ja  v a 2s  .  com

    MBDiscussion mbDiscussion = _mbDiscussionLocalService.fetchDiscussion(className, classPK);

    if (mbDiscussion == null) {
        return false;
    }

    List<String> resourceActions = ResourceActionsUtil.getResourceActions(className);

    if (!resourceActions.contains(actionId)) {
        return true;
    }

    if ((mbDiscussion.getUserId() > 0) && permissionChecker.hasOwnerPermission(companyId, className, classPK,
            mbDiscussion.getUserId(), actionId)) {

        return true;
    }

    Boolean hasPermission = BaseModelPermissionCheckerUtil.containsBaseModelPermission(permissionChecker,
            groupId, className, classPK, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }

    return permissionChecker.hasPermission(groupId, className, classPK, actionId);
}