【发布时间】:2018-09-27 07:43:36
【问题描述】:
我希望我的资源是这样的。相同的方法映射,但将根据发送请求的权限调用每个方法。有什么解决办法吗?
@RestController
@RequestMapping("/test")
public class TestResource {
@GetMapping
@PreAuthorize("hasAuthority('COMMITTEE')")
public String testForCommittee() {
return "This is a test. Custom result for committee.";
}
@GetMapping
@PreAuthorize("hasAuthority('ADMIN')")
public String testForAdmin() {
return "This is a test. Custom result for admin.";
}
}
【问题讨论】:
-
只编写了一个方法,并根据用户的权限将调用委托给另一个方法。只是一个 if 语句。
-
是的。我找不到任何解决方案,而且我已经在这样做了。不过谢谢! :)
标签: java spring spring-security spring-oauth2