Grails 如何防止登录用户使用Spring Security Core编辑其他用户?

Grails 如何防止登录用户使用Spring Security Core编辑其他用户?,grails,spring-security,Grails,Spring Security,我拥有Spring Security Core中的学生角色。学生角色可以编辑您的信息。但如果他想编辑其他用户的信息,这也是可能的 @Secured(['ROLE_STUDENT']) def edit(Student studentInstance) { respond studentInstance } @Secured(['ROLE_STUDENT']) def update(Student studentInstance) { if (studentInstance==

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

@Secured(['ROLE_STUDENT'])
def edit(Student studentInstance) {
    respond studentInstance
}

@Secured(['ROLE_STUDENT'])
def update(Student studentInstance) {

    if (studentInstance== null) {
        notFound()
        return
    }

    if (studentInstance.hasErrors()) {
        respond studentInstance.errors, view:'edit'
        return
    }

    studentInstance.save flush:true
    ...
}
如何防止学生登录编辑其他


例如,如果我键入:-我可以编辑另一个用户的信息,只更改id

使用Spring Security:s getAuthenticatedUser()获取当前登录的studentInstance,而不是基于任意提供的参数id。或者至少检查提供的参数id是否与当前登录用户的参数id匹配。

查看docsThanks@IgorArtamonov o/I中的Spring安全ACL,如下所示,但它不起作用:`安全(['ROLE_ADMIN','ROLE_STUDENT')预授权('IsAuthenticated()和main?.id==#StudentInstance.id')def edit(StudentInstance){Respond StudentInstance}'`