|
@@ -2,22 +2,10 @@ package org.springframework.security.acls.jdbc;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileInputStream;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.ObjectInputStream;
|
|
|
|
-import java.io.ObjectOutputStream;
|
|
|
|
-import java.io.Serializable;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
import net.sf.ehcache.Cache;
|
|
import net.sf.ehcache.Cache;
|
|
import net.sf.ehcache.CacheManager;
|
|
import net.sf.ehcache.CacheManager;
|
|
import net.sf.ehcache.Ehcache;
|
|
import net.sf.ehcache.Ehcache;
|
|
-
|
|
|
|
-import org.junit.After;
|
|
|
|
-import org.junit.AfterClass;
|
|
|
|
-import org.junit.BeforeClass;
|
|
|
|
-import org.junit.Test;
|
|
|
|
|
|
+import org.junit.*;
|
|
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
|
|
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
|
|
import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl;
|
|
import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl;
|
|
import org.springframework.security.acls.domain.AclImpl;
|
|
import org.springframework.security.acls.domain.AclImpl;
|
|
@@ -28,11 +16,18 @@ import org.springframework.security.acls.model.MutableAcl;
|
|
import org.springframework.security.acls.model.ObjectIdentity;
|
|
import org.springframework.security.acls.model.ObjectIdentity;
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
-import org.springframework.security.core.GrantedAuthority;
|
|
|
|
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
|
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.util.FieldUtils;
|
|
import org.springframework.security.util.FieldUtils;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.ObjectInputStream;
|
|
|
|
+import java.io.ObjectOutputStream;
|
|
|
|
+import java.io.Serializable;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Tests {@link EhCacheBasedAclCache}
|
|
* Tests {@link EhCacheBasedAclCache}
|
|
*
|
|
*
|
|
@@ -127,11 +122,11 @@ public class EhCacheBasedAclCacheTests {
|
|
// SEC-527
|
|
// SEC-527
|
|
@Test
|
|
@Test
|
|
public void testDiskSerializationOfMutableAclObjectInstance() throws Exception {
|
|
public void testDiskSerializationOfMutableAclObjectInstance() throws Exception {
|
|
- ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, new Long(100));
|
|
|
|
- AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(new GrantedAuthority[] {
|
|
|
|
|
|
+ ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100));
|
|
|
|
+ AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
- new GrantedAuthorityImpl("ROLE_GENERAL") });
|
|
|
|
- MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
+ new GrantedAuthorityImpl("ROLE_GENERAL"));
|
|
|
|
+ MutableAcl acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
// Serialization test
|
|
// Serialization test
|
|
File file = File.createTempFile("SEC_TEST", ".object");
|
|
File file = File.createTempFile("SEC_TEST", ".object");
|
|
@@ -159,11 +154,11 @@ public class EhCacheBasedAclCacheTests {
|
|
Ehcache cache = getCache();
|
|
Ehcache cache = getCache();
|
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
|
|
|
|
|
- ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, new Long(100));
|
|
|
|
- AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(new GrantedAuthority[] {
|
|
|
|
|
|
+ ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100));
|
|
|
|
+ AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
- new GrantedAuthorityImpl("ROLE_GENERAL") });
|
|
|
|
- MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
+ new GrantedAuthorityImpl("ROLE_GENERAL"));
|
|
|
|
+ MutableAcl acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
assertEquals(0, cache.getDiskStoreSize());
|
|
assertEquals(0, cache.getDiskStoreSize());
|
|
myCache.putInCache(acl);
|
|
myCache.putInCache(acl);
|
|
@@ -173,29 +168,29 @@ public class EhCacheBasedAclCacheTests {
|
|
assertFalse(cache.isElementInMemory(acl.getObjectIdentity()));
|
|
assertFalse(cache.isElementInMemory(acl.getObjectIdentity()));
|
|
|
|
|
|
// Check we can get from cache the same objects we put in
|
|
// Check we can get from cache the same objects we put in
|
|
- assertEquals(myCache.getFromCache(new Long(1)), acl);
|
|
|
|
|
|
+ assertEquals(myCache.getFromCache(Long.valueOf(1)), acl);
|
|
assertEquals(myCache.getFromCache(identity), acl);
|
|
assertEquals(myCache.getFromCache(identity), acl);
|
|
|
|
|
|
// Put another object in cache
|
|
// Put another object in cache
|
|
- ObjectIdentity identity2 = new ObjectIdentityImpl(TARGET_CLASS, new Long(101));
|
|
|
|
- MutableAcl acl2 = new AclImpl(identity2, new Long(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
+ ObjectIdentity identity2 = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(101));
|
|
|
|
+ MutableAcl acl2 = new AclImpl(identity2, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
myCache.putInCache(acl2);
|
|
myCache.putInCache(acl2);
|
|
assertEquals(cache.getSize(), 4);
|
|
assertEquals(cache.getSize(), 4);
|
|
assertEquals(4, cache.getDiskStoreSize());
|
|
assertEquals(4, cache.getDiskStoreSize());
|
|
|
|
|
|
// Try to evict an entry that doesn't exist
|
|
// Try to evict an entry that doesn't exist
|
|
- myCache.evictFromCache(new Long(3));
|
|
|
|
- myCache.evictFromCache(new ObjectIdentityImpl(TARGET_CLASS, new Long(102)));
|
|
|
|
|
|
+ myCache.evictFromCache(Long.valueOf(3));
|
|
|
|
+ myCache.evictFromCache(new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(102)));
|
|
assertEquals(cache.getSize(), 4);
|
|
assertEquals(cache.getSize(), 4);
|
|
assertEquals(4, cache.getDiskStoreSize());
|
|
assertEquals(4, cache.getDiskStoreSize());
|
|
|
|
|
|
- myCache.evictFromCache(new Long(1));
|
|
|
|
|
|
+ myCache.evictFromCache(Long.valueOf(1));
|
|
assertEquals(cache.getSize(), 2);
|
|
assertEquals(cache.getSize(), 2);
|
|
assertEquals(2, cache.getDiskStoreSize());
|
|
assertEquals(2, cache.getDiskStoreSize());
|
|
|
|
|
|
// Check the second object inserted
|
|
// Check the second object inserted
|
|
- assertEquals(myCache.getFromCache(new Long(2)), acl2);
|
|
|
|
|
|
+ assertEquals(myCache.getFromCache(Long.valueOf(2)), acl2);
|
|
assertEquals(myCache.getFromCache(identity2), acl2);
|
|
assertEquals(myCache.getFromCache(identity2), acl2);
|
|
|
|
|
|
myCache.evictFromCache(identity2);
|
|
myCache.evictFromCache(identity2);
|
|
@@ -208,18 +203,17 @@ public class EhCacheBasedAclCacheTests {
|
|
Ehcache cache = getCache();
|
|
Ehcache cache = getCache();
|
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
|
|
|
|
|
- Authentication auth = new TestingAuthenticationToken("user", "password", new GrantedAuthority[] {
|
|
|
|
- new GrantedAuthorityImpl("ROLE_GENERAL") });
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("user", "password", "ROLE_GENERAL");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
|
|
|
|
- ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, new Long(1));
|
|
|
|
- ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, new Long(2));
|
|
|
|
- AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(new GrantedAuthority[] {
|
|
|
|
|
|
+ ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(1));
|
|
|
|
+ ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2));
|
|
|
|
+ AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
new GrantedAuthorityImpl("ROLE_OWNERSHIP"), new GrantedAuthorityImpl("ROLE_AUDITING"),
|
|
- new GrantedAuthorityImpl("ROLE_GENERAL") });
|
|
|
|
- MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
- MutableAcl parentAcl = new AclImpl(identityParent, new Long(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
+ new GrantedAuthorityImpl("ROLE_GENERAL"));
|
|
|
|
+ MutableAcl acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
+ MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
|
|
|
|
|
acl.setParent(parentAcl);
|
|
acl.setParent(parentAcl);
|
|
|
|
|
|
@@ -240,7 +234,7 @@ public class EhCacheBasedAclCacheTests {
|
|
}
|
|
}
|
|
|
|
|
|
// Check we can get from cache the same objects we put in
|
|
// Check we can get from cache the same objects we put in
|
|
- AclImpl aclFromCache = (AclImpl) myCache.getFromCache(new Long(1));
|
|
|
|
|
|
+ AclImpl aclFromCache = (AclImpl) myCache.getFromCache(Long.valueOf(1));
|
|
// For the checks on transient fields, we need to be sure that the object is being loaded from the cache,
|
|
// For the checks on transient fields, we need to be sure that the object is being loaded from the cache,
|
|
// not from the ehcache spool or elsewhere...
|
|
// not from the ehcache spool or elsewhere...
|
|
assertFalse(acl == aclFromCache);
|
|
assertFalse(acl == aclFromCache);
|
|
@@ -250,7 +244,7 @@ public class EhCacheBasedAclCacheTests {
|
|
assertNotNull(FieldUtils.getFieldValue(aclFromCache.getParentAcl(), "permissionGrantingStrategy"));
|
|
assertNotNull(FieldUtils.getFieldValue(aclFromCache.getParentAcl(), "permissionGrantingStrategy"));
|
|
assertEquals(acl, myCache.getFromCache(identity));
|
|
assertEquals(acl, myCache.getFromCache(identity));
|
|
assertNotNull(FieldUtils.getFieldValue(aclFromCache, "aclAuthorizationStrategy"));
|
|
assertNotNull(FieldUtils.getFieldValue(aclFromCache, "aclAuthorizationStrategy"));
|
|
- AclImpl parentAclFromCache = (AclImpl) myCache.getFromCache(new Long(2));
|
|
|
|
|
|
+ AclImpl parentAclFromCache = (AclImpl) myCache.getFromCache(Long.valueOf(2));
|
|
assertEquals(parentAcl, parentAclFromCache);
|
|
assertEquals(parentAcl, parentAclFromCache);
|
|
assertNotNull(FieldUtils.getFieldValue(parentAclFromCache, "aclAuthorizationStrategy"));
|
|
assertNotNull(FieldUtils.getFieldValue(parentAclFromCache, "aclAuthorizationStrategy"));
|
|
assertEquals(parentAcl, myCache.getFromCache(identityParent));
|
|
assertEquals(parentAcl, myCache.getFromCache(identityParent));
|