@Test void testGetTypes() { LabelledType type1 = LabelledType.create("entity-type1", "type1", "label"); LabelledType type2 = LabelledType.create("entity-type2", "type2", "label"); LabelledType type3 = LabelledType.create("entity-type3", "type3", "label"); when(permissionService.getLabelledTypes()).thenReturn(Sets.newHashSet(type1, type2, type3)); doReturn(true) .when(userPermissionEvaluator) .hasPermission(new EntityTypeIdentity("type1"), READ); doReturn(false) .when(userPermissionEvaluator) .hasPermission(new EntityTypeIdentity("type2"), READ); doReturn(true) .when(userPermissionEvaluator) .hasPermission(new EntityTypeIdentity("type3"), READ); assertEquals(newHashSet(type1, type3), permissionServiceDecorator.getLabelledTypes()); }
@Override public Set<LabelledType> getLabelledTypes() { return permissionService.getLabelledTypes().stream() .filter( type -> userPermissionEvaluator.hasPermission( new EntityTypeIdentity(type.getEntityType()), READ)) .collect(toSet()); }
PermissionServiceDecorator implements PermissionService { @Override public Set<LabelledType> getLabelledTypes() { return permissionService.getLabelledTypes().stream() .filter( type -> userPermissionEvaluator.hasPermission( new EntityTypeIdentity(type.getEntityType()), READ)) .collect(toSet()); } }
PermissionServiceDecorator implements PermissionService { @Override public Set<LabelledType> getLabelledTypes() { return permissionService.getLabelledTypes().stream() .filter( type -> userPermissionEvaluator.hasPermission( new EntityTypeIdentity(type.getEntityType()), READ)) .collect(toSet()); } PermissionServiceDecorator(
      PermissionService permissionService,
      EntityHelper entityHelper,
      UserRoleTools userRoleTools,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceDecorator implements PermissionService { @Override public Set<LabelledType> getLabelledTypes() { return permissionService.getLabelledTypes().stream() .filter( type -> userPermissionEvaluator.hasPermission( new EntityTypeIdentity(type.getEntityType()), READ)) .collect(toSet()); } PermissionServiceDecorator(
      PermissionService permissionService,
      EntityHelper entityHelper,
      UserRoleTools userRoleTools,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override void createAcl(ObjectIdentity objectIdentity); @Override void createPermission(Permission permission); @Override void createPermissions(Set<Permission> permissions); @Override void updatePermission(Permission permission); @Override void updatePermissions(Set<Permission> permissions); @Override void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override void addType(String typeId); @Override void deleteType(String typeId); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid); }
PermissionServiceDecorator implements PermissionService { @Override public Set<LabelledType> getLabelledTypes() { return permissionService.getLabelledTypes().stream() .filter( type -> userPermissionEvaluator.hasPermission( new EntityTypeIdentity(type.getEntityType()), READ)) .collect(toSet()); } PermissionServiceDecorator(
      PermissionService permissionService,
      EntityHelper entityHelper,
      UserRoleTools userRoleTools,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override void createAcl(ObjectIdentity objectIdentity); @Override void createPermission(Permission permission); @Override void createPermissions(Set<Permission> permissions); @Override void updatePermission(Permission permission); @Override void updatePermissions(Set<Permission> permissions); @Override void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override void addType(String typeId); @Override void deleteType(String typeId); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid); static final String SUPERUSER; }