【问题标题】:Spring roo security setup with CUD but not R?使用 CUD 但不是 R 的 Spring roo 安全设置?
【发布时间】:2012-08-05 22:49:11
【问题描述】:

我正在尝试在 Spring 中设置安全策略,以便任何人都可以读取在 roo 中创建的任何实体,但只有管理员用户(在 applicationContext-security.xml 中指定)可以创建/更新/删除。在我看来,我应该能够通过自定义applicationContext-security.xml 来实现我的目标,但我想不出办法。我想过使用拦截网址,例如:

<intercept-url pattern="/anyEntity/*?form" access="hasRole('ROLE_ADMIN')" />

但此配置不包括 DELETE,因为它是 POST 中的隐藏字段(根据文档,支持 post 方法,但没有关于如何在拦截 url 标签中指定隐藏字段值的文档)

另一种方法是在实体设置方法上使用@secured。我目前依靠 roo 来生成 getter/setter,所以我想尽可能避免使用它

我还可以编写一个自定义控制器来进行我想的过滤。但在我看来,我应该能够自定义配置。我一定遗漏了一些明显的东西,因为公共只读策略应该是一种非常常见的策略。

【问题讨论】:

    标签: spring-security spring-roo


    【解决方案1】:

    我认为你可以使用method="DELETE"属性来拦截url,因为roo将隐藏的方法字段转换为http方法。

    还有更多信息here

    【讨论】:

      【解决方案2】:

      我是这样做的:

          <!-- only user role can use modify methods -->
          <intercept-url pattern="/**" method="POST" access="hasRole('ROLE_USER')" />
          <intercept-url pattern="/**" method="DELETE" access="hasRole('ROLE_USER')" />
          <intercept-url pattern="/**" method="PUT" access="hasRole('ROLE_USER')" />
          <!-- any role can use GET methods -->
          <intercept-url pattern="/**" method="GET" access="isAuthenticated()" />
          <intercept-url pattern="/**" method="HEAD" access="isAuthenticated()" />
          <intercept-url pattern="/**" method="OPTIONS" access="isAuthenticated()" />
          <intercept-url pattern="/**" method="TRACE" access="isAuthenticated()" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 2018-01-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多