2
是否有可能使用Spring數據休息和Spring安全性返回當前用戶相關的實體,使用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);
它的工作原理,謝謝! – ShaggyBathDuck
@ShaggyBathDuck不要忘記接受/ upvoted答案,幫助你... – Cepr0