是否可以使用Spring Data Rest和Spring Security返回当前用户相关实体,使用findAll()方法而不在GET查询参数中指定此用户?
我唯一的解决方案是将用户作为参数传递,但也许这是从SpringSecurityContext获取他的另一种选择
public interface InvoiceRepository extends CrudRepository<Invoice, Long> {
@RestResource
@PreAuthorize("hasRole('ROLE_ADMIN') or user?.username == authentication.name")
List<Invoice> findAllByUser(@Param("user") User user);
Run Code Online (Sandbox Code Playgroud)