Premise:
A web-service exposes its data via REST. Each record belongs to the user who created the record (row-level-security). Users may only retrieve own records.
@RepositoryRestResource(path = "talks")
public interface TalkRepository extends PagingAndSortingRepository<Talk, Long> {
@Override
@Query("select t from Talk t where t.owner.id= ?#{principal?.id}")
Page<Talk> findAll(Pageable pageable);
}
That repository is now available under a /talks
endpoint.
Question:
Is there a way 1) to expose the same domain entity at multiple endpoints and 2) define different @Query
annotations depending on the endpoint?
/talks
I'd let that be my default implementation open to admin roles/me/talks
this is the endpoint that applies row level security against the principal and as part of the/me/**
endpoints is exposed as public api to implementing clients.
This question is partially related to https://jira.spring.io/browse/DATAREST-555, but only in so far that the additional path segment is currently not supported.
Rationale:
I like the idea of not having to put too much conditional logic into SPeL queries like is owner or has_some_role
(some examples here). Further it would become easy to protect the /me/**
endpoints by different strategies than the default API (e.g. only /me/**
might be subject to OAuth2).