Example usage for com.liferay.portal.kernel.service ResourcePermissionServiceUtil removeResourcePermission

List of usage examples for com.liferay.portal.kernel.service ResourcePermissionServiceUtil removeResourcePermission

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ResourcePermissionServiceUtil removeResourcePermission.

Prototype

public static void removeResourcePermission(long groupId, long companyId, String name, int scope,
        String primKey, long roleId, String actionId)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Revokes permission at the scope from the role to perform the action on resources of the type.

Usage

From source file:com.liferay.dynamic.data.mapping.service.test.DDMStructureServiceTest.java

License:Open Source License

@Test
public void testSearchWithSiteAdminPermission() throws Exception {
    DDMStructure structure = addStructure(_classNameId, StringUtil.randomString());

    structure = addStructure(_classNameId, StringUtil.randomString());

    String modelName = ResourceActionsUtil.getCompositeModelName(PortalUtil.getClassName(_classNameId),
            DDMStructure.class.getName());

    List<Role> roles = RoleLocalServiceUtil.getRoles(TestPropsValues.getCompanyId());

    for (Role role : roles) {
        ResourcePermissionServiceUtil.removeResourcePermission(structure.getGroupId(), structure.getCompanyId(),
                modelName, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(structure.getPrimaryKey()),
                role.getRoleId(), ActionKeys.VIEW);
    }//from   w  w w  .  j  a v  a 2  s  . co m

    long[] groupIds = { group.getGroupId(), group.getGroupId() };

    List<DDMStructure> structures = DDMStructureServiceUtil.search(TestPropsValues.getCompanyId(), groupIds,
            _classNameId, StringPool.BLANK, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            null);

    Assert.assertEquals(structures.toString(), 2, structures.size());
}

From source file:com.liferay.dynamic.data.mapping.service.test.DDMStructureServiceTest.java

License:Open Source License

@Test
public void testSearchWithSiteMemberPermission() throws Exception {
    DDMStructure structure = addStructure(_classNameId, StringUtil.randomString());

    structure = addStructure(_classNameId, StringUtil.randomString());

    String modelName = ResourceActionsUtil.getCompositeModelName(PortalUtil.getClassName(_classNameId),
            DDMStructure.class.getName());

    List<Role> roles = RoleLocalServiceUtil.getRoles(TestPropsValues.getCompanyId());

    for (Role role : roles) {
        ResourcePermissionServiceUtil.removeResourcePermission(structure.getGroupId(), structure.getCompanyId(),
                modelName, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(structure.getPrimaryKey()),
                role.getRoleId(), ActionKeys.VIEW);
    }/*from w  ww  .j ava2 s  .c  o m*/

    long[] groupIds = { group.getGroupId(), group.getGroupId() };

    User siteMemberUser = UserTestUtil.addGroupUser(group, RoleConstants.SITE_MEMBER);

    PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(siteMemberUser);

    PermissionThreadLocal.setPermissionChecker(permissionChecker);

    List<DDMStructure> structures = DDMStructureServiceUtil.search(TestPropsValues.getCompanyId(), groupIds,
            _classNameId, StringPool.BLANK, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            null);

    Assert.assertEquals(structures.toString(), 1, structures.size());
}