【发布时间】:2017-04-22 19:48:25
【问题描述】:
考虑两个实体Entity 和OtherEntity 暴露为@RepositoryRestResource,通过@ManyToOne 关系链接(Entity 可能有多个OtherEntities)
您想使用 Spring Security 过滤集合资源,因此您覆盖了它们的 Repository 的 Iterable<Entity> findAll() 函数。
@RepositoryRestResource
@Repository
public interface EntityRepository extends CrudRepository<Entity, Long> {
@Override
@PostFilter("hasPermission(filterObject, 'READ')")
Iterable<Entity> findAll();
}
当调用GET /api/v1/entities 或GET /api/v1/otherEntities 时,您会得到相应权限过滤的结果。
但是在调用他们的关联资源GET /api/v1/entities/:id/otherEntities 时,检索到的OtherEntity 元素列表没有被过滤。
应该覆盖什么 Repository 函数以使关联资源也被过滤?
或者有其他方法可以实现吗?
【问题讨论】:
标签: spring spring-security spring-data-rest