【问题标题】:Field-level security using Grails 2.x with Spring Security plugin使用带有 Spring Security 插件的 Grails 2.x 的字段级安全性
【发布时间】:2014-05-23 06:26:16
【问题描述】:

是否可以使用 Grails 中的 Spring Security Core 插件实现字段级安全性?

我们目前正在使用带有@Secured 注释的方法级安全性,但是有些用户应该只能更新实体的某些字段。我们可以使用security taglib 隐藏不应访问的字段,但这只是客户端限制(因此很容易绕过)。

【问题讨论】:

    标签: grails spring-security


    【解决方案1】:

    Grails 的 Spring Security Core 插件直接不对此提供任何支持。但是,没有什么能阻止您围绕绑定编写自己的安全性。

    例如,在您的控制器中:

    package com.example
    import grails.plugin.springsecurity.SpringSecurityUtils
    class PersonController {
      ...
      def update() {
        Person personInstance = Person.get(params.id)
        if (SpringSecurityUtils.ifAllGranted('ROLE_ADMIN') {
          bindData(personInstance, params) // exclude nothing 
        } else {
          bindData(personInstance, params, [exclude: ['someSensitiveProperty', 'anotherProp']]) 
        }
      }
      ...
    }
    

    理论上,您甚至可以在您选择的绑定方法中将此绑定逻辑封装在域类本身中(例如personInstance.bindDataWithSecurity(params)

    【讨论】:

    • 我不知道这是可能的!谢谢!
    • 不用担心。如果有足够多的人需要,我可以考虑制作一个插件,允许您在域类级别配置它,并将动态生成并连接到应用程序的活页夹连接起来。
    猜你喜欢
    • 2015-10-05
    • 2016-08-30
    • 2012-12-28
    • 2013-05-19
    • 1970-01-01
    • 2015-09-19
    • 2014-02-05
    • 2011-09-14
    • 2011-11-11
    相关资源
    最近更新 更多