Skip to content

Commit

Permalink
Drop EhCache2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusdacoregio committed Nov 1, 2021
1 parent 5c4dd51 commit 5a0f1d5
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 724 deletions.
2 changes: 0 additions & 2 deletions acl/spring-security-acl.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ dependencies {
api 'org.springframework:spring-jdbc'
api 'org.springframework:spring-tx'

optional 'net.sf.ehcache:ehcache'

testImplementation "org.assertj:assertj-core"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-params"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package org.springframework.security.acls.jdbc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.sql.DataSource;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.acls.TargetObject;
import org.springframework.security.acls.TargetObjectWithUUID;
Expand All @@ -41,10 +42,10 @@
import org.springframework.security.acls.domain.ConsoleAuditLogger;
import org.springframework.security.acls.domain.DefaultPermissionFactory;
import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy;
import org.springframework.security.acls.domain.EhCacheBasedAclCache;
import org.springframework.security.acls.domain.GrantedAuthoritySid;
import org.springframework.security.acls.domain.ObjectIdentityImpl;
import org.springframework.security.acls.domain.PrincipalSid;
import org.springframework.security.acls.domain.SpringCacheBasedAclCache;
import org.springframework.security.acls.model.Acl;
import org.springframework.security.acls.model.AuditableAccessControlEntry;
import org.springframework.security.acls.model.MutableAcl;
Expand All @@ -55,6 +56,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

/**
* Tests {@link BasicLookupStrategy}
Expand All @@ -75,22 +78,21 @@ public abstract class AbstractBasicLookupStrategyTests {

private BasicLookupStrategy strategy;

private static CacheManager cacheManager;
private static CacheManagerMock cacheManager;

public abstract JdbcTemplate getJdbcTemplate();

public abstract DataSource getDataSource();

@BeforeAll
public static void initCacheManaer() {
cacheManager = CacheManager.create();
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
cacheManager = new CacheManagerMock();
cacheManager.addCache("basiclookuptestcache");
}

@AfterAll
public static void shutdownCacheManager() {
cacheManager.removalAll();
cacheManager.shutdown();
cacheManager.clear();
}

@BeforeEach
Expand Down Expand Up @@ -118,11 +120,17 @@ protected AclAuthorizationStrategy aclAuthStrategy() {
return new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_ADMINISTRATOR"));
}

protected EhCacheBasedAclCache aclCache() {
return new EhCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()),
protected SpringCacheBasedAclCache aclCache() {
return new SpringCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()),
new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_USER")));
}

protected Cache getCache() {
Cache cache = cacheManager.getCacheManager().getCache("basiclookuptestcache");
cache.clear();
return cache;
}

@AfterEach
public void emptyDatabase() {
String query = "DELETE FROM acl_entry;" + "DELETE FROM acl_object_identity WHERE ID = 9;"
Expand All @@ -134,12 +142,6 @@ public void emptyDatabase() {
getJdbcTemplate().execute(query);
}

protected Ehcache getCache() {
Ehcache cache = cacheManager.getCache("basiclookuptestcache");
cache.removeAll();
return cache;
}

@Test
public void testAclsRetrievalWithDefaultBatchSize() throws Exception {
ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, 100L);
Expand Down Expand Up @@ -318,4 +320,32 @@ public void testCreateGrantedAuthority() {
assertThat(((GrantedAuthoritySid) result).getGrantedAuthority()).isEqualTo("sid");
}

private static final class CacheManagerMock {

private final List<String> cacheNames;

private final CacheManager cacheManager;

private CacheManagerMock() {
this.cacheNames = new ArrayList<>();
this.cacheManager = mock(CacheManager.class);
given(this.cacheManager.getCacheNames()).willReturn(this.cacheNames);
}

private CacheManager getCacheManager() {
return this.cacheManager;
}

private void addCache(String name) {
this.cacheNames.add(name);
Cache cache = new ConcurrentMapCache(name);
given(this.cacheManager.getCache(name)).willReturn(cache);
}

private void clear() {
this.cacheNames.clear();
}

}

}
Loading

0 comments on commit 5a0f1d5

Please sign in to comment.