Spring OAuth2:如何只允许用户使用他自己的 ID 访问 /rest/users/{id}?
Spring OAuth2: How can I only allow user to access /rest/users/{id} with his own id?
有时我们只允许用户通过调用 /rest/users/{id} 访问他自己的信息,我如何在 spring OAuth2 下实现这个?
谢谢。
假设您的 Principal 是您的用户 ID,请使用 @PreAuthorize 注释:
@PreAuthorize("#id.equals(principal)")
public void myMethod(Long id)
有时我们只允许用户通过调用 /rest/users/{id} 访问他自己的信息,我如何在 spring OAuth2 下实现这个?
谢谢。
假设您的 Principal 是您的用户 ID,请使用 @PreAuthorize 注释:
@PreAuthorize("#id.equals(principal)")
public void myMethod(Long id)