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

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

Introduction

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

Prototype

public boolean hasPermission(long groupId, String name, String primKey, String actionId);

Source Link

Document

Returns true if the user has permission to perform the action on the resource.

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 w  w w . j av a 2 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();
    }/*w  w  w  .  j av a2 s  .  com*/

    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();
    }/* w  w  w .  j a  va2s. c o  m*/

    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) {// ww  w.j  av  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.DDLPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, long groupId, String portletId,
        String actionId) {//from   www  . jav a  2  s . c  o  m

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, groupId, RESOURCE_NAME,
            groupId, portletId, actionId);

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

    return permissionChecker.hasPermission(groupId, RESOURCE_NAME, groupId, actionId);
}

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();
        }//w w w  .j  a  v  a  2  s .c o  m
    }

    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();
    }/*ww w  .j  av a 2 s  . c  om*/

    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) {//from   w  ww  .  j a  v a  2 s  .c  o 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();
        }//  w  ww  .  ja v  a 2 s . com
    }

    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;
    }//www . jav  a  2s .  c  o  m

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