Skip to content

Commit 5a0f1d5

Browse files
Drop EhCache2 support
Issue spring-projectsgh-10363
1 parent 5c4dd51 commit 5a0f1d5

File tree

13 files changed

+54
-724
lines changed

13 files changed

+54
-724
lines changed

acl/spring-security-acl.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ dependencies {
99
api 'org.springframework:spring-jdbc'
1010
api 'org.springframework:spring-tx'
1111

12-
optional 'net.sf.ehcache:ehcache'
13-
1412
testImplementation "org.assertj:assertj-core"
1513
testImplementation "org.junit.jupiter:junit-jupiter-api"
1614
testImplementation "org.junit.jupiter:junit-jupiter-params"

acl/src/main/java/org/springframework/security/acls/domain/EhCacheBasedAclCache.java

Lines changed: 0 additions & 141 deletions
This file was deleted.

acl/src/test/java/org/springframework/security/acls/jdbc/AbstractBasicLookupStrategyTests.java

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@
1616

1717
package org.springframework.security.acls.jdbc;
1818

19+
import java.util.ArrayList;
1920
import java.util.Arrays;
2021
import java.util.List;
2122
import java.util.Map;
2223
import java.util.UUID;
2324

2425
import javax.sql.DataSource;
2526

26-
import net.sf.ehcache.Cache;
27-
import net.sf.ehcache.CacheManager;
28-
import net.sf.ehcache.Ehcache;
2927
import org.junit.jupiter.api.AfterAll;
3028
import org.junit.jupiter.api.AfterEach;
3129
import org.junit.jupiter.api.BeforeAll;
3230
import org.junit.jupiter.api.BeforeEach;
3331
import org.junit.jupiter.api.Test;
3432

33+
import org.springframework.cache.Cache;
34+
import org.springframework.cache.CacheManager;
35+
import org.springframework.cache.concurrent.ConcurrentMapCache;
3536
import org.springframework.jdbc.core.JdbcTemplate;
3637
import org.springframework.security.acls.TargetObject;
3738
import org.springframework.security.acls.TargetObjectWithUUID;
@@ -41,10 +42,10 @@
4142
import org.springframework.security.acls.domain.ConsoleAuditLogger;
4243
import org.springframework.security.acls.domain.DefaultPermissionFactory;
4344
import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy;
44-
import org.springframework.security.acls.domain.EhCacheBasedAclCache;
4545
import org.springframework.security.acls.domain.GrantedAuthoritySid;
4646
import org.springframework.security.acls.domain.ObjectIdentityImpl;
4747
import org.springframework.security.acls.domain.PrincipalSid;
48+
import org.springframework.security.acls.domain.SpringCacheBasedAclCache;
4849
import org.springframework.security.acls.model.Acl;
4950
import org.springframework.security.acls.model.AuditableAccessControlEntry;
5051
import org.springframework.security.acls.model.MutableAcl;
@@ -55,6 +56,8 @@
5556

5657
import static org.assertj.core.api.Assertions.assertThat;
5758
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
59+
import static org.mockito.BDDMockito.given;
60+
import static org.mockito.Mockito.mock;
5861

5962
/**
6063
* Tests {@link BasicLookupStrategy}
@@ -75,22 +78,21 @@ public abstract class AbstractBasicLookupStrategyTests {
7578

7679
private BasicLookupStrategy strategy;
7780

78-
private static CacheManager cacheManager;
81+
private static CacheManagerMock cacheManager;
7982

8083
public abstract JdbcTemplate getJdbcTemplate();
8184

8285
public abstract DataSource getDataSource();
8386

8487
@BeforeAll
8588
public static void initCacheManaer() {
86-
cacheManager = CacheManager.create();
87-
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
89+
cacheManager = new CacheManagerMock();
90+
cacheManager.addCache("basiclookuptestcache");
8891
}
8992

9093
@AfterAll
9194
public static void shutdownCacheManager() {
92-
cacheManager.removalAll();
93-
cacheManager.shutdown();
95+
cacheManager.clear();
9496
}
9597

9698
@BeforeEach
@@ -118,11 +120,17 @@ protected AclAuthorizationStrategy aclAuthStrategy() {
118120
return new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_ADMINISTRATOR"));
119121
}
120122

121-
protected EhCacheBasedAclCache aclCache() {
122-
return new EhCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()),
123+
protected SpringCacheBasedAclCache aclCache() {
124+
return new SpringCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()),
123125
new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_USER")));
124126
}
125127

128+
protected Cache getCache() {
129+
Cache cache = cacheManager.getCacheManager().getCache("basiclookuptestcache");
130+
cache.clear();
131+
return cache;
132+
}
133+
126134
@AfterEach
127135
public void emptyDatabase() {
128136
String query = "DELETE FROM acl_entry;" + "DELETE FROM acl_object_identity WHERE ID = 9;"
@@ -134,12 +142,6 @@ public void emptyDatabase() {
134142
getJdbcTemplate().execute(query);
135143
}
136144

137-
protected Ehcache getCache() {
138-
Ehcache cache = cacheManager.getCache("basiclookuptestcache");
139-
cache.removeAll();
140-
return cache;
141-
}
142-
143145
@Test
144146
public void testAclsRetrievalWithDefaultBatchSize() throws Exception {
145147
ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, 100L);
@@ -318,4 +320,32 @@ public void testCreateGrantedAuthority() {
318320
assertThat(((GrantedAuthoritySid) result).getGrantedAuthority()).isEqualTo("sid");
319321
}
320322

323+
private static final class CacheManagerMock {
324+
325+
private final List<String> cacheNames;
326+
327+
private final CacheManager cacheManager;
328+
329+
private CacheManagerMock() {
330+
this.cacheNames = new ArrayList<>();
331+
this.cacheManager = mock(CacheManager.class);
332+
given(this.cacheManager.getCacheNames()).willReturn(this.cacheNames);
333+
}
334+
335+
private CacheManager getCacheManager() {
336+
return this.cacheManager;
337+
}
338+
339+
private void addCache(String name) {
340+
this.cacheNames.add(name);
341+
Cache cache = new ConcurrentMapCache(name);
342+
given(this.cacheManager.getCache(name)).willReturn(cache);
343+
}
344+
345+
private void clear() {
346+
this.cacheNames.clear();
347+
}
348+
349+
}
350+
321351
}

0 commit comments

Comments
 (0)