我在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
...
}
如何防止学生登录编辑其他?
例如,如果我输入:http://localhost:8080/app/student/edit/1 - 我可以编辑另一个只更改ID的用户的信息
答案 0 :(得分:0)
使用Spring Security:s getAuthenticatedUser()来获取当前登录的studentInstance,而不是基于任意提供的params id。或者至少检查提供的params id是否与当前登录用户的id相匹配。