From 10f477e63524cfcf01a4abff9016d9266a1e5a17 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Sun, 11 Feb 2024 23:37:30 +0200 Subject: [PATCH] JAVA-29285 Upgrade spring-security-acl (#15821) Co-authored-by: timis1 --- .../spring-security-acl/pom.xml | 13 ++------ .../com/baeldung/acl/config/ACLContext.java | 23 +++---------- .../acl/persistence/entity/NoticeMessage.java | 8 ++--- .../src/main/resources/acl-data.sql | 32 +++++++++---------- .../java/com/baeldung/SpringContextTest.java | 2 ++ 5 files changed, 29 insertions(+), 49 deletions(-) diff --git a/spring-security-modules/spring-security-acl/pom.xml b/spring-security-modules/spring-security-acl/pom.xml index 734b85800a..4feea8fb96 100644 --- a/spring-security-modules/spring-security-acl/pom.xml +++ b/spring-security-modules/spring-security-acl/pom.xml @@ -11,7 +11,8 @@ com.baeldung - spring-security-modules + parent-boot-3 + ../../parent-boot-3 0.0.1-SNAPSHOT @@ -46,16 +47,6 @@ org.springframework spring-context-support - - net.sf.ehcache - ehcache-core - ${ehcache-core.version} - jar - - - 2.6.11 - - \ No newline at end of file diff --git a/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java index cb60ef1d45..186cadbb63 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java @@ -4,8 +4,7 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cache.ehcache.EhCacheFactoryBean; -import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; +import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; @@ -16,7 +15,7 @@ import org.springframework.security.acls.domain.AclAuthorizationStrategy; import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl; import org.springframework.security.acls.domain.ConsoleAuditLogger; import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy; -import org.springframework.security.acls.domain.EhCacheBasedAclCache; +import org.springframework.security.acls.domain.SpringCacheBasedAclCache; import org.springframework.security.acls.jdbc.BasicLookupStrategy; import org.springframework.security.acls.jdbc.JdbcMutableAclService; import org.springframework.security.acls.jdbc.LookupStrategy; @@ -31,21 +30,9 @@ public class ACLContext { DataSource dataSource; @Bean - public EhCacheBasedAclCache aclCache() { - return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(), permissionGrantingStrategy(), aclAuthorizationStrategy()); - } - - @Bean - public EhCacheFactoryBean aclEhCacheFactoryBean() { - EhCacheFactoryBean ehCacheFactoryBean = new EhCacheFactoryBean(); - ehCacheFactoryBean.setCacheManager(aclCacheManager().getObject()); - ehCacheFactoryBean.setCacheName("aclCache"); - return ehCacheFactoryBean; - } - - @Bean - public EhCacheManagerFactoryBean aclCacheManager() { - return new EhCacheManagerFactoryBean(); + public SpringCacheBasedAclCache aclCache() { + final ConcurrentMapCache aclCache = new ConcurrentMapCache("acl_cache"); + return new SpringCacheBasedAclCache(aclCache, permissionGrantingStrategy(), aclAuthorizationStrategy()); } @Bean diff --git a/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java index 80c04146e4..c1de3112bf 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java @@ -1,9 +1,9 @@ package com.baeldung.acl.persistence.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; @Entity @Table(name="system_message") diff --git a/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql b/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql index 3b48c83f3c..f4c443961c 100644 --- a/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql +++ b/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql @@ -1,7 +1,7 @@ -INSERT INTO acl_sid (id, principal, sid) VALUES -(1, 1, 'manager'), -(2, 1, 'hr'), -(3, 0, 'ROLE_EDITOR'); +INSERT INTO acl_sid (principal, sid) VALUES +(1, 'manager'), +(1, 'hr'), +(0, 'ROLE_EDITOR'); INSERT INTO acl_class (id, class) VALUES (1, 'com.baeldung.acl.persistence.entity.NoticeMessage'); @@ -11,16 +11,16 @@ INSERT INTO system_message(id,content) VALUES (2,'Second Level Message'), (3,'Third Level Message'); -INSERT INTO acl_object_identity (id, object_id_class, object_id_identity, parent_object, owner_sid, entries_inheriting) VALUES -(1, 1, 1, NULL, 3, 0), -(2, 1, 2, NULL, 3, 0), -(3, 1, 3, NULL, 3, 0); +INSERT INTO acl_object_identity (object_id_class, object_id_identity, parent_object, owner_sid, entries_inheriting) VALUES +(1, 1, NULL, 3, 0), +(1, 2, NULL, 3, 0), +(1, 3, NULL, 3, 0); -INSERT INTO acl_entry (id, acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) VALUES -(1, 1, 1, 1, 1, 1, 1, 1), -(2, 1, 2, 1, 2, 1, 1, 1), -(3, 1, 3, 3, 1, 1, 1, 1), -(4, 2, 1, 2, 1, 1, 1, 1), -(5, 2, 2, 3, 1, 1, 1, 1), -(6, 3, 1, 3, 1, 1, 1, 1), -(7, 3, 2, 3, 2, 1, 1, 1); \ No newline at end of file +INSERT INTO acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) VALUES +(1, 1, 1, 1, 1, 1, 1), +(1, 2, 1, 2, 1, 1, 1), +(1, 3, 3, 1, 1, 1, 1), +(2, 1, 2, 1, 1, 1, 1), +(2, 2, 3, 1, 1, 1, 1), +(3, 1, 3, 1, 1, 1, 1), +(3, 2, 3, 2, 1, 1, 1); \ No newline at end of file diff --git a/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java index e60983733e..fa8ad73a80 100644 --- a/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java @@ -4,10 +4,12 @@ import com.baeldung.acl.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) +@DirtiesContext public class SpringContextTest { @Test