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

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

Introduction

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

Prototype

public boolean hasOwnerPermission(long companyId, String name, String primKey, long ownerId, String actionId);

Source Link

Document

Returns true if the user is the owner of the resource and has permission to perform the action.

Usage

From source file:ca.efendi.datafeeds.service.permission.CJProductPermission.java

License:Apache License

public static boolean contains(PermissionChecker permissionChecker, CJProduct entry, String actionId) {

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

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            CJProduct.class.getName(), entry.getProductId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }//from www  . jav  a2  s. c  om

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

            return false;
        }
    } else if (entry.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
                CJProduct.class.getName(), entry.getProductId(), actionId);

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

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), CJProduct.class.getName(),
            entry.getProductId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), CJProduct.class.getName(), entry.getProductId(),
            actionId);
}

From source file:com.liferay.blogs.service.permission.BlogsEntryPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, BlogsEntry entry, String actionId) {

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

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            BlogsEntry.class.getName(), entry.getEntryId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/*from w w  w . j  a v  a2  s.  co  m*/

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

            return false;
        }
    } else if (entry.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
                BlogsEntry.class.getName(), entry.getEntryId(), actionId);

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

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), BlogsEntry.class.getName(),
            entry.getEntryId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
            actionId);
}

From source file:com.liferay.bookmarks.service.permission.BookmarksEntryPermissionChecker.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, BookmarksEntry entry, String actionId)
        throws PortalException {

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            BookmarksEntry.class.getName(), entry.getEntryId(), BookmarksPortletKeys.BOOKMARKS, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/*from ww  w  .jav a 2  s  . c om*/

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

        long folderId = entry.getFolderId();

        if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            if (!BookmarksResourcePermissionChecker.contains(permissionChecker, entry.getGroupId(), actionId)) {

                return false;
            }
        } else {
            try {
                BookmarksFolder folder = _bookmarksFolderLocalService.getFolder(folderId);

                if (!BookmarksFolderPermissionChecker.contains(permissionChecker, folder, ActionKeys.ACCESS)
                        && !BookmarksFolderPermissionChecker.contains(permissionChecker, folder,
                                ActionKeys.VIEW)) {

                    return false;
                }
            } catch (NoSuchFolderException nsfe) {
                if (!entry.isInTrash()) {
                    throw nsfe;
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), BookmarksEntry.class.getName(),
            entry.getEntryId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), BookmarksEntry.class.getName(),
            entry.getEntryId(), actionId);
}

From source file:com.liferay.bookmarks.service.permission.BookmarksFolderPermissionChecker.java

License:Open Source License

private static boolean _hasPermission(PermissionChecker permissionChecker, BookmarksFolder folder,
        String actionId) {//from  ww  w. j  a v  a  2s .c  o m

    if (permissionChecker.hasOwnerPermission(folder.getCompanyId(), BookmarksFolder.class.getName(),
            folder.getFolderId(), folder.getUserId(), actionId)
            || permissionChecker.hasPermission(folder.getGroupId(), BookmarksFolder.class.getName(),
                    folder.getFolderId(), actionId)) {

        return true;
    }

    return false;
}

From source file:com.liferay.dynamic.data.lists.service.permission.DDLRecordSetPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, DDLRecordSet recordSet, String actionId) {

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

    if (!actionId.equals(DDLActionKeys.ADD_RECORD)
            && (recordSet.getScope() == DDLRecordSetConstants.SCOPE_DYNAMIC_DATA_LISTS)) {

        Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, recordSet.getGroupId(),
                DDLRecordSet.class.getName(), recordSet.getRecordSetId(), portletId, actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }/*from   w w  w . ja  v  a2s . com*/
    }

    if (permissionChecker.hasOwnerPermission(recordSet.getCompanyId(), DDLRecordSet.class.getName(),
            recordSet.getRecordSetId(), recordSet.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(recordSet.getGroupId(), DDLRecordSet.class.getName(),
            recordSet.getRecordSetId(), actionId);
}

From source file:com.liferay.dynamic.data.mapping.service.permission.DDMDataProviderInstancePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker,
        DDMDataProviderInstance dataProviderInstance, String actionId) {

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

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker,
            dataProviderInstance.getGroupId(), DDMDataProviderInstance.class.getName(),
            dataProviderInstance.getDataProviderInstanceId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }//w  w  w.ja v  a 2 s . c o m

    if (permissionChecker.hasOwnerPermission(dataProviderInstance.getCompanyId(),
            DDMDataProviderInstance.class.getName(), dataProviderInstance.getDataProviderInstanceId(),
            dataProviderInstance.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(dataProviderInstance.getGroupId(),
            DDMDataProviderInstance.class.getName(), dataProviderInstance.getDataProviderInstanceId(),
            actionId);
}

From source file:com.liferay.dynamic.data.mapping.service.permission.DDMFormInstancePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, DDMFormInstance ddmFormInstance,
        String actionId) {/* w  w  w.  j  av  a 2  s .  co  m*/

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

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, ddmFormInstance.getGroupId(),
            DDMFormInstance.class.getName(), ddmFormInstance.getFormInstanceId(), portletId, actionId);

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

    if (permissionChecker.hasOwnerPermission(ddmFormInstance.getCompanyId(), DDMFormInstance.class.getName(),
            ddmFormInstance.getFormInstanceId(), ddmFormInstance.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(ddmFormInstance.getGroupId(), DDMFormInstance.class.getName(),
            ddmFormInstance.getFormInstanceId(), actionId);
}

From source file:com.liferay.dynamic.data.mapping.service.permission.DDMStructurePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, DDMStructure structure, String portletId,
        String actionId) throws PortalException {

    String structureModelResourceName = getStructureModelResourceName(structure.getClassName());

    if (Validator.isNotNull(portletId)) {
        Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, structure.getGroupId(),
                structureModelResourceName, structure.getStructureId(), portletId, actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }//from www  .j  av  a  2  s . c  o  m
    }

    if (permissionChecker.hasOwnerPermission(structure.getCompanyId(), structureModelResourceName,
            structure.getStructureId(), structure.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(structure.getGroupId(), structureModelResourceName,
            structure.getStructureId(), actionId);
}

From source file:com.liferay.dynamic.data.mapping.service.permission.DDMTemplatePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, DDMTemplate template, String actionId)
        throws PortalException {

    String templateModelResourceName = getTemplateModelResourceName(template.getResourceClassName());

    if (permissionChecker.hasOwnerPermission(template.getCompanyId(), templateModelResourceName,
            template.getTemplateId(), template.getUserId(), actionId)) {

        return true;
    }/* ww w  .j  a v a2 s . c  om*/

    return permissionChecker.hasPermission(template.getGroupId(), templateModelResourceName,
            template.getTemplateId(), actionId);
}

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();
    }/*from w  w  w .  ja  v a 2  s.  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);
}