0

我拥有 Spring Security Core 中的角色 student。角色学生可以编辑您的信息。但如果他想编辑另一个用户的信息,这也是可能的。

@Secured(['ROLE_ADMIN','ROLE_STUDENT'])
@PreAuthorize('isAuthenticated() and principal?.id == #studentInstance.id')
def edit(Student studentInstance) {
    respond studentInstance
}

我使用了 ACL 插件,但它不起作用。您仍然可以编辑其他学生。

4

1 回答 1

1

您可以@Secured在控制器中使用,因为核心插件会查找它们并为您构建相应的访问规则检查,但控制器中不支持任何其他 Spring Security 注释。

相反,注释一个服务方法并从控制器调用它。Spring Security 将带注释的 Spring bean(例如服务)包装在执行检查的代理中,并且只有在检查成功时才调用 bean 方法。

于 2015-05-27T19:05:08.940 回答