@Test void testFindAllQuerySkipLimit() { Entity permittedEntity0 = mock(Entity.class); Entity notPermittedEntity0 = mock(Entity.class); Entity permittedEntity1 = mock(Entity.class); Entity notPermittedEntity1 = mock(Entity.class); Entity permittedEntity2 = mock(Entity.class); when(delegateRepository.findAll(new QueryImpl<>().offset(0).pageSize(Integer.MAX_VALUE))) .thenReturn( Stream.of( permittedEntity0, notPermittedEntity0, permittedEntity1, notPermittedEntity1, permittedEntity2)); doReturn(true).when(permissionChecker).isReadAllowed(permittedEntity0); doReturn(false).when(permissionChecker).isReadAllowed(notPermittedEntity0); doReturn(true).when(permissionChecker).isReadAllowed(permittedEntity1); assertEquals( singletonList(permittedEntity1), permissionCheckingDecorator .findAll(new QueryImpl<>().offset(1).pageSize(1)) .collect(toList())); }
@Override public Stream<E> findAll(Query<E> q) { Query<E> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<E> permittedEntityStream = delegate().findAll(qWithoutLimitOffset).filter(permissionChecker::isReadAllowed); permittedEntityStream = skipAndLimitStream(permittedEntityStream, q); return permittedEntityStream; }
PermissionCheckingDecorator extends AbstractRepositoryDecorator<E> { @Override public Stream<E> findAll(Query<E> q) { Query<E> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<E> permittedEntityStream = delegate().findAll(qWithoutLimitOffset).filter(permissionChecker::isReadAllowed); permittedEntityStream = skipAndLimitStream(permittedEntityStream, q); return permittedEntityStream; } }
PermissionCheckingDecorator extends AbstractRepositoryDecorator<E> { @Override public Stream<E> findAll(Query<E> q) { Query<E> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<E> permittedEntityStream = delegate().findAll(qWithoutLimitOffset).filter(permissionChecker::isReadAllowed); permittedEntityStream = skipAndLimitStream(permittedEntityStream, q); return permittedEntityStream; } PermissionCheckingDecorator(
      Repository<E> delegateRepository, PermissionChecker<E> permissionChecker); }
PermissionCheckingDecorator extends AbstractRepositoryDecorator<E> { @Override public Stream<E> findAll(Query<E> q) { Query<E> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<E> permittedEntityStream = delegate().findAll(qWithoutLimitOffset).filter(permissionChecker::isReadAllowed); permittedEntityStream = skipAndLimitStream(permittedEntityStream, q); return permittedEntityStream; } PermissionCheckingDecorator(
      Repository<E> delegateRepository, PermissionChecker<E> permissionChecker); @Override @Nonnull Iterator<E> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<E>> consumer, int batchSize); @Override long count(); @Override long count(Query<E> q); @Override Stream<E> findAll(Query<E> q); @Override E findOne(Query<E> q); @Override E findOneById(Object id); @Override E findOneById(Object id, Fetch fetch); @Override Stream<E> findAll(Stream<Object> ids); @Override Stream<E> findAll(Stream<Object> ids, Fetch fetch); @Override void update(E entity); @Override void update(Stream<E> entities); @Override void delete(E entity); @Override void delete(Stream<E> entities); @Override void deleteById(Object id); @Transactional @Override void deleteAll(Stream<Object> ids); @Transactional @Override void deleteAll(); @Override void add(E entity); @Override Integer add(Stream<E> entities); @Override AggregateResult aggregate(AggregateQuery aggregateQuery); }
PermissionCheckingDecorator extends AbstractRepositoryDecorator<E> { @Override public Stream<E> findAll(Query<E> q) { Query<E> qWithoutLimitOffset = new QueryImpl<>(q); qWithoutLimitOffset.offset(0).pageSize(Integer.MAX_VALUE); Stream<E> permittedEntityStream = delegate().findAll(qWithoutLimitOffset).filter(permissionChecker::isReadAllowed); permittedEntityStream = skipAndLimitStream(permittedEntityStream, q); return permittedEntityStream; } PermissionCheckingDecorator(
      Repository<E> delegateRepository, PermissionChecker<E> permissionChecker); @Override @Nonnull Iterator<E> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<E>> consumer, int batchSize); @Override long count(); @Override long count(Query<E> q); @Override Stream<E> findAll(Query<E> q); @Override E findOne(Query<E> q); @Override E findOneById(Object id); @Override E findOneById(Object id, Fetch fetch); @Override Stream<E> findAll(Stream<Object> ids); @Override Stream<E> findAll(Stream<Object> ids, Fetch fetch); @Override void update(E entity); @Override void update(Stream<E> entities); @Override void delete(E entity); @Override void delete(Stream<E> entities); @Override void deleteById(Object id); @Transactional @Override void deleteAll(Stream<Object> ids); @Transactional @Override void deleteAll(); @Override void add(E entity); @Override Integer add(Stream<E> entities); @Override AggregateResult aggregate(AggregateQuery aggregateQuery);  }