【问题标题】:JCache ACL Cache for Spring Security用于 Spring Security 的 JCache ACL 缓存
【发布时间】:2014-06-11 21:39:00
【问题描述】:

我正在使用 Spring Security ACL,它需要定义缓存。到目前为止,我一直在使用这个:

@Bean(name = { "defaultAclCache", "aclCache" })
protected AclCache defaultAclCache() {
    return new SpringCacheBasedAclCache(defaultAclJCacheFactory(), defaultPermissionGrantingStrategy(), defaultAclAuthorizationStrategy());
}

一切正常。但是,我切换到使用jcache,现在defaultAclJCacheFactory() 返回一个与SpringCacheBasedAclCache 不兼容的javax.cache.Cache 实例:

@Bean(name = { "defaultAclJCacheFactory", "aclJCacheFactory" })
protected Cache defaultAclJCacheFactory() {
    return cacheManager.getCache("acl_cache");
}

我试图搜索org.springframework.security.acls.model.AclCacheJCache 实现,但只有一个用于spring 缓存和一个用于EhCache。有没有计划为jcache介绍一个?

【问题讨论】:

    标签: spring spring-security spring-security-acl jcache


    【解决方案1】:

    您应该能够使用JCacheCacheManager 实现来获取org.springframework.cache.Cache 的实例例如:

    @Bean(name = { "defaultAclCache", "aclCache" })
    protected AclCache defaultAclCache(org.springframework.cache.CacheManager springCacheManager) {
        org.springframework.cache.Cache cache = 
            springCacheManager.getCache("acl_cache");
        return new SpringCacheBasedAclCache(cache, 
            defaultPermissionGrantingStrategy(), 
            defaultAclAuthorizationStrategy());
    }
    
    // Depending on your configuration, you may not even need this
    @Bean
    public JCacheCacheManager springCacheManager(javax.cache.CacheManager cacheManager) {
        return new JCacheCacheManager(cacheManager);
    }
    

    【讨论】:

    • 为什么“取决于你的配置......”
    • 为什么我在 Spring 文档或示例中找不到这方面的规范示例?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多