【问题标题】:Prevent access to another user using Grails SpringSecutiryCore使用 Grails SpringSecutiryCore 防止访问其他用户
【发布时间】:2015-10-23 20:21:47
【问题描述】:

我有以下问题, 如何防止用户使用 SpringSecurityCore 访问另一个用户?

例如,阻止学生访问其他学生的数据。当时两者具有相同的角色(角色学生) 如果我这样做 student/show/1 我可以查看和编辑数据。我要阻止它!

我可以使用 ACL 插件,使用 @PreAuthorize 标记,但它已被弃用,并且在 2.5.1 版本的 Grails 中出现错误。

跟在 ACL 中一样:只有 ADMIN 和登录的学生有访问权限。

@PreAuthorize("(hasRole('ROLE_ADMIN')) or (isAuthenticated()) and (principal.id==#studentInstance.id)")

【问题讨论】:

    标签: grails spring-security


    【解决方案1】:

    您可以在方法级别使用@Secured 注释。然后像您已经在做的那样比较主体 ID。最后,render 主体不匹配时的 403 状态。

    render(status: 503)
    

    【讨论】:

    • 哈哈!它发生在我们所有人身上。
    猜你喜欢
    • 2013-12-04
    • 2018-04-27
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多