6

我尝试更新到 EhCache 3,但注意到我的 spring-security-acl 的 AclConfig 不再有效。原因EhCacheBasedAclCache仍然是使用import net.sf.ehcache.Ehcache。EhCacheorg.ehcache从版本 3 开始移动,因此不再有效。spring 是否为 EhCache 3 提供了替代类,或者我需要实现自己的 Acl Cache?这是代码,不再有效:

@Bean
public EhCacheBasedAclCache aclCache() {
    return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(),
            permissionGrantingStrategy(), aclAuthorizationStrategy());
}
4

1 回答 1

4

我在您的问题中添加了赏金,因为我也在寻找更权威的答案。
这是一个可行的解决方案,但可能有更好的方法和缓存设置可以专门针对 acl 进行调整。

1)JdbcMutableAclService接受任何AclCache实现,而不仅仅是EhCacheBasedAclCache. 立即可用的实现是SpringCacheBasedAclCache. 你也可以实现你自己的。

2) 在项目中启用 ehcache3,使用 Spring Cache 作为抽象。在 Spring Boot 中,这就像使用@EnableCache注解一样简单。然后添加@Autowired CacheManager cacheManager你的 bean 配置类。

3) 使用 aclCache 注释的条目更新您的 ehcache3.xml
- 关键是Serializable因为 Spring acl 插入在 Long 和 ObjectIdentity 上键入的缓存条目:)

    <cache alias="aclCache">
        <key-type>java.io.Serializable</key-type>
        <value-type>org.springframework.security.acls.model.MutableAcl</value-type>
        <expiry>
            <ttl unit="seconds">3600</ttl>
        </expiry>
        <resources>
            <heap unit="entries">2000</heap>
            <offheap unit="MB">10</offheap>
        </resources>
    </cache>

4)用这样的替换你的EhCacheBasedAclCachebean :SpringCacheBasedAclCache

    @Bean
    public AclCache aclCache() {
        return new SpringCacheBasedAclCache(
                cacheManager.getCache("aclCache"), 
                permissionGrantingStrategy(), 
                aclAuthorizationStrategy());        
    }

5)aclCache()JdbcMutableAclService构造函数中使用

于 2020-03-09T12:14:52.987 回答