【问题标题】:Can Spring Security ACLs be applied on the domain class level?Spring Security ACL 可以应用于域类级别吗?
【发布时间】:2012-11-07 11:17:40
【问题描述】:

是否可以对域类(而不是域实例)应用 ACL 权限?我有一个场景,我想为一类用户提供对域对象完全 CRUD 的全面权限,而另一类用户必须具有特定的 ACL 条目才能执行此操作。

当然可以将 ACL 条目与基于角色的权限混合来实现这一点,但我觉得除了实例级别之外,Spring ACL 可以在类级别上工作,这是一种更优雅的解决方案。

我正在查看微薄的Spring Security ACL documentationthis question

【问题讨论】:

    标签: spring-security acl


    【解决方案1】:

    看一下界面ObjectIdentity。它表示系统中受保护的对象。

    /**
     * Obtains the actual identifier. This identifier must not be reused to represent other domain objects with
     * the same javaType.
     *
     * Because ACLs are largely immutable, it is strongly recommended to use
     * a synthetic identifier (such as a database sequence number for the primary key). Do not use an identifier with
     * business meaning, as that business meaning may change in the future such change will cascade to the ACL
     * subsystem data.
     *
     * @return the identifier (unique within this type; never null)
     */
    Serializable getIdentifier();
    
    /**
     * Obtains the "type" metadata for the domain object. This will often be a Java type name (an interface or a class)
     * – traditionally it is the name of the domain object implementation class.
     *
     * @return the "type" of the domain object (never null).
     */
    String getType();
    

    如您所见,Spring Security 使用Serializable 来描述标识符的类型。 所以可以使用带类名的String。

    您需要更新 SQL 架构,因为 Spring Security 的作者假设大多数人会通过长/整数 id 来识别对象。

    create table acl_object_identity(
    ...
    object_id_class bigint not null,
    object_id_identity bigint not null,
    

    正如我所检查的,JdbcMutableAclService 能够处理该自定义,因为它仅使用 ObjectIdentity 接口。

    研究org.springframework.security.acls包的源代码。

    【讨论】:

      猜你喜欢
      • 2013-11-07
      • 1970-01-01
      • 2014-11-21
      • 2015-10-13
      • 1970-01-01
      • 2014-02-15
      • 2020-04-10
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多