在spring-security-acl中允许ObjectIdentity.getIdentifier()的UUID值

p_w*_*eel 5 acl spring-security

我想讨论提供一种解决方案,以允许在SEC-972的 spring-security-acl中为ObjectIdentity.getIdentifier()提供UUID值。Spring Security贡献准则指向Spring Security论坛,这些论坛现已关闭并且指向Stack Overflow,因此希望我在正确的位置提出要求。

我的解决方案在acl_class表中添加了新列class_id_type,该列可以有选择地允许您为该acl_class指定Java类型。如果将ConversionService连接到BasicLookupStrategy,并且acl_class指定了class_id_type,则ConversionService将用于将标识符转换为正确的类型。这增加了对spring-core的依赖。

acl_class模式如下所示:

create table acl_class(
    id bigint generated by default as identity(start with 100) not null primary key,
    class varchar_ignorecase(100) not null,
    class_id_type varchar_ignorecase(100),
    constraint unique_uk_2 unique(class)
);
Run Code Online (Sandbox Code Playgroud)

然后,lookupStrategy的定义如下所示:

<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"/>
<!-- Declare a lookup strategy-->
<bean id="lookupStrategy" class="org.springframework.security.acls.jdbc.BasicLookupStrategy">
    <constructor-arg ref="dataSource"/>
    <constructor-arg ref="aclCache"/>
    <constructor-arg ref="aclAuthorizationStrategy"/>
    <constructor-arg ref="permissionGrantingStrategy"/>
    <constructor-arg ref="conversionService"/>
    <property name="permissionFactory" ref="permissionFactory"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

对BasicLookupStrategy.convertCurrentResultIntoObject()的调整如下所示:

// If the Java type is a String, check to see if we can convert it to the target id type, e.g. UUID.
Serializable identifier = (Serializable) rs.getObject("object_id_identity");
if (isString(identifier) && hasValidClassIdType(rs)
        && canConvertFromStringTo(classIdTypeFrom(rs))) {

    identifier = convertFromStringTo((String) identifier, classIdTypeFrom(rs));
}
ObjectIdentity objectIdentity = new ObjectIdentityImpl(rs.getString("class"),
        identifier);
Run Code Online (Sandbox Code Playgroud)

您可以在此fork中查看分支中的更改-https: //github.com/pwheel/spring-security/tree/feature/acl-uuid-strings

该分支包含一些不相关的更改(例如,私有Maven存储库),因此请不要认为该分支本身具有拉取请求。这项变更似乎是“不平凡的”变更,因此,根据提出的指导原则,在提出请求之前,我想进行讨论。

还要注意我在应用程序中发现我需要实现一个JdbcMutableAclService版本,该版本使用以SQL Types作为参数的JdbcTemplate方法-这是因为否则MySQL连接器会将UUID映射为二进制而不是String,从而导致UTF-8错误被抛出。我可以将其添加到请求请求中。

我正在生产中使用此设置,没有任何问题。

在提出拉取请求之前,我应该进行任何更改或改进吗?

谢谢