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

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

Introduction

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

Prototype

public long getCompanyId();

Source Link

Document

Returns the primary key of the user's company.

Usage

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

License:Open Source License

@Override
public List<AssetEntry> getAssetEntries(PortletRequest portletRequest, PortletPreferences portletPreferences,
        PermissionChecker permissionChecker, long[] groupIds, boolean deleteMissingAssetEntries,
        boolean checkPermission, boolean includeNonVisibleAssets, int type) throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;/*from   w w  w  . jav a 2  s  .  co  m*/

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        _removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

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

License:Open Source License

public static List<AssetEntry> getAssetEntries(PortletRequest portletRequest,
        PortletPreferences portletPreferences, PermissionChecker permissionChecker, long[] groupIds,
        boolean deleteMissingAssetEntries, boolean checkPermission, boolean includeNonVisibleAssets, int type)
        throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;/*w w  w . j av a 2 s .  c  om*/

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

From source file:com.liferay.calendar.web.internal.asset.CalendarBookingAssetRendererFactory.java

License:Open Source License

@Override
public boolean hasAddPermission(PermissionChecker permissionChecker, long groupId, long classTypeId)
        throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(permissionChecker.getCompanyId());

    CalendarResource calendarResource = CalendarResourceUtil.getScopeGroupCalendarResource(groupId,
            serviceContext);/* w w  w. ja v a 2  s  .  co m*/

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

    Calendar calendar = calendarResource.getDefaultCalendar();

    return CalendarPermission.contains(permissionChecker, calendar.getCalendarId(),
            CalendarActionKeys.MANAGE_BOOKINGS);
}

From source file:com.liferay.journal.service.permission.JournalArticlePermission.java

License:Open Source License

private static boolean _contains(PermissionChecker permissionChecker, JournalArticle article, String actionId) {

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

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
            JournalArticle.class.getName(), article.getResourcePrimKey(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }//  ww  w .  ja  v  a2s  .  co m

    if (article.isDraft()) {
        if (actionId.equals(ActionKeys.VIEW) && !contains(permissionChecker, article, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (article.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
                JournalArticle.class.getName(), article.getResourcePrimKey(), actionId);

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

    if (actionId.equals(ActionKeys.VIEW)) {
        JournalServiceConfiguration journalServiceConfiguration = null;

        try {
            journalServiceConfiguration = _configurationProvider.getCompanyConfiguration(
                    JournalServiceConfiguration.class, permissionChecker.getCompanyId());
        } catch (ConfigurationException ce) {
            _log.error("Unable to get journal service configuration for company "
                    + permissionChecker.getCompanyId(), ce);

            return false;
        }

        if (!journalServiceConfiguration.articleViewPermissionsCheckEnabled()) {

            return true;
        }

        if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
            long folderId = article.getFolderId();

            if (folderId == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

                if (!JournalPermission.contains(permissionChecker, article.getGroupId(), actionId)) {

                    return false;
                }
            } else {
                JournalFolder folder = _journalFolderLocalService.fetchFolder(folderId);

                if (folder != null) {
                    if (!JournalFolderPermission.contains(permissionChecker, folder, ActionKeys.ACCESS)
                            && !JournalFolderPermission.contains(permissionChecker, folder, ActionKeys.VIEW)) {

                        return false;
                    }
                } else {
                    if (!article.isInTrash()) {
                        _log.error("Unable to get journal folder " + folderId);

                        return false;
                    }
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(article.getCompanyId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), article.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(article.getGroupId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), actionId);
}

From source file:com.liferay.site.admin.web.internal.portlet.SiteAdminControlPanelEntry.java

License:Open Source License

@Override
protected boolean hasPermissionImplicitlyGranted(PermissionChecker permissionChecker, Group group,
        Portlet portlet) throws Exception {

    if (PropsValues.SITES_CONTROL_PANEL_MEMBERS_VISIBLE) {
        LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

        groupParams.put("site", Boolean.TRUE);
        groupParams.put("usersGroups", permissionChecker.getUserId());

        int count = _groupLocalService.searchCount(permissionChecker.getCompanyId(), null, null, groupParams);

        if (count > 0) {
            return true;
        }//from   ww w . j a  v  a 2s.c  o m
    }

    return super.hasPermissionImplicitlyGranted(permissionChecker, group, portlet);
}