我在Spring Security Core中拥有该角色。学生可以编辑您的信息。但如果他想编辑其他用户的信息也是可能的。
@Secured(['ROLE_ADMIN','ROLE_STUDENT'])
@PreAuthorize('isAuthenticated() and principal?.id == #studentInstance.id')
def edit(Student studentInstance) {
respond studentInstance
}
我使用了ACL插件,但它没有用。你仍然可以编辑另一个学生。
答案 0 :(得分:1)
您可以在控制器中使用@Secured
,因为核心插件会查找它们并为您构建相应的访问规则检查,但控制器中不支持任何其他Spring Security注释。
相反,注释一个服务方法并从控制器中调用它。 Spring Security在执行检查的代理中包装带注释的Spring bean(例如服务),并且只有在检查成功时才调用bean方法。