Petar Tahchiev
Petar Tahchiev

Reputation: 4376

JCache ACL Cache for Spring Security

I'm using Spring Security ACL and it needs to have cache defined. So far I was using this:

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

and it all worked fine. However, I switched to use jcache and now defaultAclJCacheFactory() returns an instance of javax.cache.Cache which is incompatible with the SpringCacheBasedAclCache:

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

I tried to search for a JCache implementation of org.springframework.security.acls.model.AclCache but there's only this one for spring cache and one for EhCache. Is there any plans to introduce one for jcache?

Upvotes: 1

Views: 1878

Answers (1)

Rob Winch
Rob Winch

Reputation: 21720

You should be able to use JCacheCacheManager implementation to obtain an instance of org.springframework.cache.Cache For example:

@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);
}

Upvotes: 4

Related Questions