春季休息-拼字游戏不会影响某些粗俗的方法

时间:2019-01-20 18:10:08

标签: java crud spring-rest

所以我正在用Spring创建一个rest api。我想限制getById,以便只有用户才能看到自己的帐户。 delete限制有效

#account.user?.username == authentication.name 

但不限制deleteByIdgetById。我不知道spel语法是否有问题或您是否无法限制这些方法。

interface AccountRepository : CrudRepository<Account, Long> {

@PreAuthorize("@accountRepository.findOne(#id)?.user?.username == authentication.name or hasRole('ROLE_ADMIN')")
override fun deleteById(@Param("id") id: Long)

@PreAuthorize("#account.user?.username == authentication.name or hasRole('ROLE_ADMIN')")
override fun delete(@Param("account") entity: Account)

@PreAuthorize("@accountRepository.findOne(#id)?.user?.username == authentication.name or hasRole('ROLE_ADMIN')")
override fun findById(@Param("id") id: Long): Optional<Account>

@PreAuthorize("hasRole('ROLE_ADMIN')")
override fun findAll(): MutableIterable<Account>

@RestResource(exported = false)
override fun <S : Account?> save(entity: S): S
}

因此,当用户ID错误的用户发送对其他帐户的请求时,他们应该会收到403 forbidden响应,但实际上他们会收到200响应,并且可以看到其他用户的信息。

0 个答案:

没有答案
相关问题