gpt4 book ai didi

grails - 如何防止已登录的用户使用Spring Security Core编辑其他用户?

转载 作者:行者123 更新时间:2023-12-02 16:01:25 24 4
gpt4 key购买 nike

我在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的另一个用户的信息

最佳答案

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

关于grails - 如何防止已登录的用户使用Spring Security Core编辑其他用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com