Spring Data REST filtering data based on the user

前端 未结 4 1943
無奈伤痛
無奈伤痛 2020-12-15 11:25

If I have a repository setup like the following, making use of Spring Data REST, I can access the data at /receipts and see all data. However, I want to only return data fo

4条回答
  •  北海茫月
    2020-12-15 12:10

    If you use Spring Security you can use this approach:

    @PreAuthorize("isFullyAuthenticated() && (#userName == principal.username)")
    public List findByUserName(@Param("userName")String userName);
    

提交回复
热议问题