【问题标题】:Spring OAuth2: How can I only allow user to access /rest/users/{id} with his own id?Spring OAuth2:我怎样才能只允许用户使用自己的 id 访问 /rest/users/{id}?
【发布时间】:2018-12-30 15:39:33
【问题描述】:

有时我们只允许用户通过调用 /rest/users/{id} 来访问他自己的信息,我该如何在 spring OAuth2 下实现呢?

谢谢。

【问题讨论】:

标签: spring spring-security oauth-2.0 spring-security-oauth2


【解决方案1】:

假设您的 Principal 是您的用户 ID,请使用 @PreAuthorize 注释:

@PreAuthorize("#id.equals(principal)")
public void myMethod(Long id)

【讨论】:

    猜你喜欢
    • 2021-04-06
    • 2019-07-21
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多