ResourceTypePermissionValidator { public boolean isValidResourceType(ResourceType resourceType, String resourceId) { if (resourceType.equals(ActivityResourceType.PERSPECTIVE) && appFormerActivities.getAllPerpectivesIds().contains(resourceId)) { return true; } else if (resourceType.equals(ActivityResourceType.EDITOR) && appFormerActivities.getAllEditorIds().contains(resourceId)) { return true; } else if (resourceType.equals(OrganizationalUnit.RESOURCE_TYPE)) { return organizationalUnitService.getOrganizationalUnits().stream() .anyMatch(orgUnit -> resourceId.equals(orgUnit.getName())); } else if (resourceType.equals(Repository.RESOURCE_TYPE)) { return projectService.getAllWorkspaceProjects().stream() .anyMatch(project -> resourceId.equals(project.getName())); } return false; } ResourceTypePermissionValidator(); @Inject  ResourceTypePermissionValidator(@Customizable final AppFormerActivities appFormerActivities, final OrganizationalUnitService organizationalUnitService,
                                           final WorkspaceProjectService projectService, final PermissionManager permissionManager); Set<Map.Entry<ResourceType, List<PermissionAction>>> getPermissionEntries(); boolean isPermissionAllowed(ResourceType resourceType, ResourceAction permissionType); Optional<PermissionAction> resourceDependancy(ResourceType resourceType, ResourceAction permissionType); boolean satisfyDependancies(PermissionCollection pc, ResourceType resourceType, ResourceAction resourceAction); boolean isValidResourceType(ResourceType resourceType, String resourceId);  }
@Test public void testIsValidSpaceType() { OrganizationalUnit ou1 = new OrganizationalUnitImpl("ou1", "defaultGroupID"); OrganizationalUnit ou2 = new OrganizationalUnitImpl("ou2", "defaultGroupID"); final List<OrganizationalUnit> allOUs = new Lists.Builder<OrganizationalUnit>() .add(ou2).add(ou1).build(); doReturn(allOUs).when(organizationalUnitService).getOrganizationalUnits(); assertTrue(permissionValidator.isValidResourceType(OrganizationalUnit.RESOURCE_TYPE, "ou1")); }
@Test public void testIsValidPerpectiveType() { doReturn(new Lists.Builder<String>().add("ExperimentalFeaturesPerspective").build()).when(appFormerActivities).getAllPerpectivesIds(); assertTrue(permissionValidator.isValidResourceType(ActivityResourceType.PERSPECTIVE, "ExperimentalFeaturesPerspective")); assertFalse(permissionValidator.isValidResourceType(ActivityResourceType.PERSPECTIVE, "TestPerspective")); }
@Test public void testIsValidEditorType() { doReturn(new Lists.Builder<String>().add("BPMNDiagramEditor").build()).when(appFormerActivities).getAllEditorIds(); assertTrue(permissionValidator.isValidResourceType(ActivityResourceType.EDITOR, "BPMNDiagramEditor")); assertFalse(permissionValidator.isValidResourceType(ActivityResourceType.EDITOR, "TestEditor")); }
@Test public void testIsValidRepositoryType() { WorkspaceProject itemB = mock(WorkspaceProject.class); when(itemB.getName()).thenReturn("Item B"); when(projectService.getAllWorkspaceProjects()).thenReturn(new Sets.Builder<WorkspaceProject>().add(itemB).build()); assertTrue(permissionValidator.isValidResourceType(Repository.RESOURCE_TYPE, "Item B")); assertFalse(permissionValidator.isValidResourceType(Repository.RESOURCE_TYPE, "Item A")); }