我试图更新到EhCache 3,但是注意到我的AclConfig for spring-security-acl不再工作了。原因是EhCacheBasedAclCache仍然使用import net.sf.ehcache.Ehcache。从版本3开始,EhCache迁移到了org.ehcache,因此这种方式不再有效。spring是否为EhCache 3提供了替换类,或者我是否需要实现自己的Acl Cache?下面是不再有效的代码:
@Bean
public EhCacheBasedAclCache aclCache() {
return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(),
permissionGrantingStrategy(), aclAuthorizationStrategy());
}发布于 2020-03-09 20:14:53
我在你的问题中添加了赏金,因为我也在寻找一个更权威的答案。
这里有一个有效的解决方案,但也可能有更好的方法&缓存设置可以专门针对acl进行调优。
1) JdbcMutableAclService接受任何AclCache实现,而不仅仅是EhCacheBasedAclCache。立即可用的实现是SpringCacheBasedAclCache。你也可以实现你自己的。
2)在您的项目中启用ehcache3,Spring Cache作为抽象。在Spring Boot中,这和使用@EnableCache注解一样简单。然后在bean配置类中添加@Autowired CacheManager cacheManager。
3)使用aclCache条目更新ehcache3.xml
注意- key是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)使用SpringCacheBasedAclCache替换您的EhCacheBasedAclCache bean,如下所示:
@Bean
public AclCache aclCache() {
return new SpringCacheBasedAclCache(
cacheManager.getCache("aclCache"),
permissionGrantingStrategy(),
aclAuthorizationStrategy());
}5)在JdbcMutableAclService构造函数中使用aclCache()
https://stackoverflow.com/questions/56157479
复制相似问题