Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security ACL with EhCache 3

I tried to update to EhCache 3, but noticed that my AclConfig for spring-security-acl no longer works. The reason is EhCacheBasedAclCache still uses import net.sf.ehcache.Ehcache. EhCache moved to org.ehcache since version 3 and thus this no longer works. Is there a replacement class provided by spring for EhCache 3 or would i need to implement my own Acl Cache? This is the code, which no longer works:

@Bean
public EhCacheBasedAclCache aclCache() {
    return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(),
            permissionGrantingStrategy(), aclAuthorizationStrategy());
}
like image 954
puelo Avatar asked May 15 '19 20:05

puelo


People also ask

What is Spring Security ACL?

Spring Security Access Control List is a Spring component which supports Domain Object Security. Simply put, Spring ACL helps in defining permissions for specific user/role on a single domain object – instead of across the board, at the typical per-operation level.

Which interface is used to represent a permission in Spring Security?

Permission. Interfaces and shared classes to manage access control lists (ACLs) for domain object instances. Basic implementation of access control lists (ACLs) interfaces.

What is ACL in Java?

An Access Control List (ACL) is a data structure that guards access to resources. The java. security. acl package provides the interface to such a data structure and the sun.


1 Answers

I added bounty to your question because I'm also looking for a more authoritative answer.
Here's a solution that works, but there could be a better approach & cache settings could be tuned specifically for acl.

1) The JdbcMutableAclService accepts any AclCache implementation, not just EhCacheBasedAclCache. Immediately available implementation is SpringCacheBasedAclCache. You could also implement your own.

2) Enable ehcache3 in your project with Spring Cache as abstraction. In Spring Boot this is as simple as using @EnableCache annotation. Then add @Autowired CacheManager cacheManager in your bean configuration class.

3) Update your ehcache3.xml with entry for aclCache
note - key is Serializable because Spring acl inserts cache entries keyed on both Long and 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) Replace your EhCacheBasedAclCache bean with SpringCacheBasedAclCache like so:

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

5) Use aclCache() in JdbcMutableAclService constructor

like image 174
Michal Avatar answered Oct 18 '22 18:10

Michal