mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-05 10:12:36 +00:00
SEC-679: Removed use of MockApplicationContext and improved use of ehcache (shutting down cache managers after tests are run). Upgraded ehcache version to 1.3 as used in Spring pom.
This commit is contained in:
parent
ca9e64f857
commit
5187f89fe8
@ -37,7 +37,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sf.ehcache</groupId>
|
<groupId>net.sf.ehcache</groupId>
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
<version>1.2.4</version>
|
<version>1.3.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -4,19 +4,19 @@ import java.util.Map;
|
|||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
import org.springframework.security.TestDataSource;
|
import org.springframework.security.TestDataSource;
|
||||||
import org.springframework.security.acls.Acl;
|
import org.springframework.security.acls.Acl;
|
||||||
import org.springframework.security.acls.AuditableAccessControlEntry;
|
import org.springframework.security.acls.AuditableAccessControlEntry;
|
||||||
@ -45,7 +45,14 @@ public class BasicLookupStrategyTests {
|
|||||||
|
|
||||||
private static TestDataSource dataSource;
|
private static TestDataSource dataSource;
|
||||||
|
|
||||||
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
@BeforeClass
|
||||||
|
public static void initCacheManaer() {
|
||||||
|
cacheManager = new CacheManager();
|
||||||
|
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createDatabase() throws Exception {
|
public static void createDatabase() throws Exception {
|
||||||
@ -62,6 +69,12 @@ public class BasicLookupStrategyTests {
|
|||||||
dataSource.destroy();
|
dataSource.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
|
cacheManager.removalAll();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void populateDatabase() {
|
public void populateDatabase() {
|
||||||
String query = "INSERT INTO acl_sid(ID,PRINCIPAL,SID) VALUES (1,1,'ben');"
|
String query = "INSERT INTO acl_sid(ID,PRINCIPAL,SID) VALUES (1,1,'ben');"
|
||||||
@ -96,8 +109,9 @@ public class BasicLookupStrategyTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Ehcache getCache() {
|
private Ehcache getCache() {
|
||||||
ApplicationContext ctx = MockApplicationContext.getContext();
|
Ehcache cache = cacheManager.getCache("basiclookuptestcache");
|
||||||
return (Ehcache) ctx.getBean("eHCacheBackend");
|
cache.removeAll();
|
||||||
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -202,7 +216,7 @@ public class BasicLookupStrategyTests {
|
|||||||
Assert.assertEquals(child.getEntries()[0].getSid(), new PrincipalSid("ben"));
|
Assert.assertEquals(child.getEntries()[0].getSid(), new PrincipalSid("ben"));
|
||||||
Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditFailure());
|
Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditFailure());
|
||||||
Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditSuccess());
|
Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditSuccess());
|
||||||
Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isGranting());
|
Assert.assertFalse((child.getEntries()[0]).isGranting());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2,16 +2,13 @@ package org.springframework.security.acls.jdbc;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Cache;
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
|
||||||
import org.springframework.context.support.AbstractXmlApplicationContext;
|
|
||||||
import org.springframework.security.Authentication;
|
import org.springframework.security.Authentication;
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
import org.springframework.security.acls.MutableAcl;
|
import org.springframework.security.acls.MutableAcl;
|
||||||
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;
|
||||||
@ -22,93 +19,105 @@ import org.springframework.security.acls.objectidentity.ObjectIdentityImpl;
|
|||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link EhCacheBasedAclCache}
|
* Tests {@link EhCacheBasedAclCache}
|
||||||
*
|
*
|
||||||
* @author Andrei Stefan
|
* @author Andrei Stefan
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedAclCacheTests extends TestCase {
|
public class EhCacheBasedAclCacheTests {
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
private static CacheManager cacheManager;
|
||||||
AbstractXmlApplicationContext ctx;
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
@BeforeClass
|
||||||
|
public static void initCacheManaer() {
|
||||||
|
cacheManager = new CacheManager();
|
||||||
|
cacheManager.addCache(new Cache("ehcachebasedacltests", 500, false, false, 30, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
|
cacheManager.removalAll();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void clearContext() {
|
||||||
|
SecurityContextHolder.clearContext();
|
||||||
|
}
|
||||||
|
|
||||||
private Ehcache getCache() {
|
private Ehcache getCache() {
|
||||||
this.ctx = (AbstractXmlApplicationContext) MockApplicationContext.getContext();
|
Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
|
||||||
|
cache.removeAll();
|
||||||
|
|
||||||
return (Ehcache) ctx.getBean("eHCacheBackend");
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
@Test(expected=IllegalArgumentException.class)
|
||||||
super.tearDown();
|
public void constructorRejectsNullParameters() throws Exception {
|
||||||
SecurityContextHolder.clearContext();
|
|
||||||
if (ctx != null) {
|
|
||||||
ctx.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConstructorRejectsNullParameters() throws Exception {
|
|
||||||
try {
|
|
||||||
AclCache aclCache = new EhCacheBasedAclCache(null);
|
AclCache aclCache = new EhCacheBasedAclCache(null);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
Assert.assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMethodsRejectNullParameters() throws Exception {
|
@Test
|
||||||
|
public void methodsRejectNullParameters() throws Exception {
|
||||||
Ehcache cache = new MockEhcache();
|
Ehcache cache = new MockEhcache();
|
||||||
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Serializable id = null;
|
Serializable id = null;
|
||||||
myCache.evictFromCache(id);
|
myCache.evictFromCache(id);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
Assert.assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ObjectIdentity obj = null;
|
ObjectIdentity obj = null;
|
||||||
myCache.evictFromCache(obj);
|
myCache.evictFromCache(obj);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
Assert.assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Serializable id = null;
|
Serializable id = null;
|
||||||
myCache.getFromCache(id);
|
myCache.getFromCache(id);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
Assert.assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ObjectIdentity obj = null;
|
ObjectIdentity obj = null;
|
||||||
myCache.getFromCache(obj);
|
myCache.getFromCache(obj);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
Assert.assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MutableAcl acl = null;
|
MutableAcl acl = null;
|
||||||
myCache.putInCache(acl);
|
myCache.putInCache(acl);
|
||||||
Assert.fail("It should have thrown IllegalArgumentException");
|
fail("It should have thrown IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
Assert.assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCacheOperationsAclWithoutParent() throws Exception {
|
@Test
|
||||||
|
public void cacheOperationsAclWithoutParent() throws Exception {
|
||||||
Ehcache cache = getCache();
|
Ehcache cache = getCache();
|
||||||
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
||||||
|
|
||||||
@ -119,36 +128,37 @@ public class EhCacheBasedAclCacheTests extends TestCase {
|
|||||||
MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
||||||
|
|
||||||
myCache.putInCache(acl);
|
myCache.putInCache(acl);
|
||||||
Assert.assertEquals(cache.getSize(), 2);
|
assertEquals(cache.getSize(), 2);
|
||||||
|
|
||||||
// Check we can get from cache the same objects we put in
|
// Check we can get from cache the same objects we put in
|
||||||
Assert.assertEquals(myCache.getFromCache(new Long(1)), acl);
|
assertEquals(myCache.getFromCache(new Long(1)), acl);
|
||||||
Assert.assertEquals(myCache.getFromCache(identity), acl);
|
assertEquals(myCache.getFromCache(identity), acl);
|
||||||
|
|
||||||
// Put another object in cache
|
// Put another object in cache
|
||||||
ObjectIdentity identity2 = new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(101));
|
ObjectIdentity identity2 = new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(101));
|
||||||
MutableAcl acl2 = new AclImpl(identity2, new Long(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
MutableAcl acl2 = new AclImpl(identity2, new Long(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
|
||||||
|
|
||||||
myCache.putInCache(acl2);
|
myCache.putInCache(acl2);
|
||||||
Assert.assertEquals(cache.getSize(), 4);
|
assertEquals(cache.getSize(), 4);
|
||||||
|
|
||||||
// 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 Long(3));
|
||||||
myCache.evictFromCache(new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(102)));
|
myCache.evictFromCache(new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(102)));
|
||||||
Assert.assertEquals(cache.getSize(), 4);
|
assertEquals(cache.getSize(), 4);
|
||||||
|
|
||||||
myCache.evictFromCache(new Long(1));
|
myCache.evictFromCache(new Long(1));
|
||||||
Assert.assertEquals(cache.getSize(), 2);
|
assertEquals(cache.getSize(), 2);
|
||||||
|
|
||||||
// Check the second object inserted
|
// Check the second object inserted
|
||||||
Assert.assertEquals(myCache.getFromCache(new Long(2)), acl2);
|
assertEquals(myCache.getFromCache(new Long(2)), acl2);
|
||||||
Assert.assertEquals(myCache.getFromCache(identity2), acl2);
|
assertEquals(myCache.getFromCache(identity2), acl2);
|
||||||
|
|
||||||
myCache.evictFromCache(identity2);
|
myCache.evictFromCache(identity2);
|
||||||
Assert.assertEquals(cache.getSize(), 0);
|
assertEquals(cache.getSize(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCacheOperationsAclWithParent() throws Exception {
|
@Test
|
||||||
|
public void cacheOperationsAclWithParent() throws Exception {
|
||||||
Ehcache cache = getCache();
|
Ehcache cache = getCache();
|
||||||
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
|
||||||
|
|
||||||
@ -168,13 +178,13 @@ public class EhCacheBasedAclCacheTests extends TestCase {
|
|||||||
acl.setParent(parentAcl);
|
acl.setParent(parentAcl);
|
||||||
|
|
||||||
myCache.putInCache(acl);
|
myCache.putInCache(acl);
|
||||||
Assert.assertEquals(cache.getSize(), 4);
|
assertEquals(cache.getSize(), 4);
|
||||||
|
|
||||||
// Check we can get from cache the same objects we put in
|
// Check we can get from cache the same objects we put in
|
||||||
Assert.assertEquals(myCache.getFromCache(new Long(1)), acl);
|
assertEquals(myCache.getFromCache(new Long(1)), acl);
|
||||||
Assert.assertEquals(myCache.getFromCache(identity), acl);
|
assertEquals(myCache.getFromCache(identity), acl);
|
||||||
Assert.assertEquals(myCache.getFromCache(new Long(2)), parentAcl);
|
assertEquals(myCache.getFromCache(new Long(2)), parentAcl);
|
||||||
Assert.assertEquals(myCache.getFromCache(identityParent), parentAcl);
|
assertEquals(myCache.getFromCache(identityParent), parentAcl);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Inner Classes ==================================================================================================
|
//~ Inner Classes ==================================================================================================
|
||||||
|
@ -41,7 +41,7 @@ import static org.junit.Assert.*;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedTicketCacheTests {
|
public class EhCacheBasedTicketCacheTests {
|
||||||
static CacheManager cacheManager;
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.security;
|
|
||||||
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simply returns an <code>ApplicationContext</code> which has a couple of <code>ApplicationEvent</code> listeners.
|
|
||||||
*
|
|
||||||
* @author Ben Alex
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class MockApplicationContext {
|
|
||||||
//~ Methods ========================================================================================================
|
|
||||||
|
|
||||||
public static ConfigurableApplicationContext getContext() {
|
|
||||||
return new ClassPathXmlApplicationContext("org/springframework/security/applicationContext.xml");
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,18 +15,19 @@
|
|||||||
|
|
||||||
package org.springframework.security.acl.basic.cache;
|
package org.springframework.security.acl.basic.cache;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
import org.springframework.security.MockApplicationContext;
|
import net.sf.ehcache.Cache;
|
||||||
|
|
||||||
import org.springframework.security.acl.basic.AclObjectIdentity;
|
import org.springframework.security.acl.basic.AclObjectIdentity;
|
||||||
import org.springframework.security.acl.basic.BasicAclEntry;
|
import org.springframework.security.acl.basic.BasicAclEntry;
|
||||||
import org.springframework.security.acl.basic.NamedEntityObjectIdentity;
|
import org.springframework.security.acl.basic.NamedEntityObjectIdentity;
|
||||||
import org.springframework.security.acl.basic.SimpleAclEntry;
|
import org.springframework.security.acl.basic.SimpleAclEntry;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,7 @@ import org.springframework.context.ApplicationContext;
|
|||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedAclEntryCacheTests extends TestCase {
|
public class EhCacheBasedAclEntryCacheTests {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
private static final AclObjectIdentity OBJECT_100 = new NamedEntityObjectIdentity("OBJECT", "100");
|
private static final AclObjectIdentity OBJECT_100 = new NamedEntityObjectIdentity("OBJECT", "100");
|
||||||
@ -44,29 +45,31 @@ public class EhCacheBasedAclEntryCacheTests extends TestCase {
|
|||||||
private static final BasicAclEntry OBJECT_100_SCOTT = new SimpleAclEntry("scott", OBJECT_100, null, 4);
|
private static final BasicAclEntry OBJECT_100_SCOTT = new SimpleAclEntry("scott", OBJECT_100, null, 4);
|
||||||
private static final BasicAclEntry OBJECT_200_PETER = new SimpleAclEntry("peter", OBJECT_200, null, 4);
|
private static final BasicAclEntry OBJECT_200_PETER = new SimpleAclEntry("peter", OBJECT_200, null, 4);
|
||||||
|
|
||||||
//~ Constructors ===================================================================================================
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
public EhCacheBasedAclEntryCacheTests() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EhCacheBasedAclEntryCacheTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void initCacheManaer() {
|
||||||
|
cacheManager = new CacheManager();
|
||||||
|
cacheManager.addCache(new Cache("ehcachebasedacltests", 500, false, false, 30, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
|
cacheManager.removalAll();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
private Ehcache getCache() {
|
private Ehcache getCache() {
|
||||||
ApplicationContext ctx = MockApplicationContext.getContext();
|
Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
|
||||||
|
cache.removeAll();
|
||||||
|
|
||||||
return (Ehcache) ctx.getBean("eHCacheBackend");
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
@Test
|
||||||
super.setUp();
|
public void cacheOperationSucceeds() throws Exception {
|
||||||
}
|
|
||||||
|
|
||||||
public void testCacheOperation() throws Exception {
|
|
||||||
EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
|
EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
|
||||||
cache.setCache(getCache());
|
cache.setCache(getCache());
|
||||||
cache.afterPropertiesSet();
|
cache.afterPropertiesSet();
|
||||||
@ -85,7 +88,8 @@ public class EhCacheBasedAclEntryCacheTests extends TestCase {
|
|||||||
assertNull(cache.getEntriesFromCache(new NamedEntityObjectIdentity("OBJECT", "100")));
|
assertNull(cache.getEntriesFromCache(new NamedEntityObjectIdentity("OBJECT", "100")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStartupDetectsMissingCache() throws Exception {
|
@Test
|
||||||
|
public void startupDetectsMissingCache() throws Exception {
|
||||||
EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
|
EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -21,11 +21,11 @@ import org.springframework.security.AccessDeniedException;
|
|||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockAccessDecisionManager;
|
import org.springframework.security.MockAccessDecisionManager;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
import org.springframework.security.MockAuthenticationManager;
|
import org.springframework.security.MockAuthenticationManager;
|
||||||
import org.springframework.security.MockJoinPoint;
|
import org.springframework.security.MockJoinPoint;
|
||||||
import org.springframework.security.MockRunAsManager;
|
import org.springframework.security.MockRunAsManager;
|
||||||
import org.springframework.security.TargetObject;
|
import org.springframework.security.TargetObject;
|
||||||
|
import org.springframework.security.MockApplicationEventPublisher;
|
||||||
|
|
||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
|||||||
|
|
||||||
public void testCallbackIsInvokedWhenPermissionGranted() throws Exception {
|
public void testCallbackIsInvokedWhenPermissionGranted() throws Exception {
|
||||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
|
||||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||||
si.setRunAsManager(new MockRunAsManager());
|
si.setRunAsManager(new MockRunAsManager());
|
||||||
@ -97,7 +97,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
|||||||
|
|
||||||
public void testCallbackIsNotInvokedWhenPermissionDenied() throws Exception {
|
public void testCallbackIsNotInvokedWhenPermissionDenied() throws Exception {
|
||||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
|
||||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||||
si.setRunAsManager(new MockRunAsManager());
|
si.setRunAsManager(new MockRunAsManager());
|
||||||
|
@ -25,10 +25,10 @@ import org.springframework.security.ConfigAttributeDefinition;
|
|||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockAccessDecisionManager;
|
import org.springframework.security.MockAccessDecisionManager;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
import org.springframework.security.MockAuthenticationManager;
|
import org.springframework.security.MockAuthenticationManager;
|
||||||
import org.springframework.security.MockRunAsManager;
|
import org.springframework.security.MockRunAsManager;
|
||||||
import org.springframework.security.RunAsManager;
|
import org.springframework.security.RunAsManager;
|
||||||
|
import org.springframework.security.MockApplicationEventPublisher;
|
||||||
import org.springframework.security.util.AntUrlPathMatcher;
|
import org.springframework.security.util.AntUrlPathMatcher;
|
||||||
import org.springframework.security.util.RegexUrlPathMatcher;
|
import org.springframework.security.util.RegexUrlPathMatcher;
|
||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
@ -141,7 +141,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
|||||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||||
interceptor.setRunAsManager(new MockRunAsManager());
|
interceptor.setRunAsManager(new MockRunAsManager());
|
||||||
interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
|
interceptor.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
|
||||||
|
|
||||||
// Setup a mock config attribute definition
|
// Setup a mock config attribute definition
|
||||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");
|
ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");
|
||||||
@ -194,7 +194,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
|||||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||||
interceptor.setRunAsManager(new MockRunAsManager());
|
interceptor.setRunAsManager(new MockRunAsManager());
|
||||||
interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
|
interceptor.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
|
||||||
|
|
||||||
// Setup a mock config attribute definition
|
// Setup a mock config attribute definition
|
||||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");
|
ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");
|
||||||
|
@ -15,18 +15,20 @@
|
|||||||
|
|
||||||
package org.springframework.security.providers.dao.cache;
|
package org.springframework.security.providers.dao.cache;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
|
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
|
|
||||||
import org.springframework.security.userdetails.User;
|
import org.springframework.security.userdetails.User;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link EhCacheBasedUserCache}.
|
* Tests {@link EhCacheBasedUserCache}.
|
||||||
@ -34,22 +36,27 @@ import org.springframework.context.ApplicationContext;
|
|||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedUserCacheTests extends TestCase {
|
public class EhCacheBasedUserCacheTests {
|
||||||
//~ Constructors ===================================================================================================
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
public EhCacheBasedUserCacheTests() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EhCacheBasedUserCacheTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
@BeforeClass
|
||||||
|
public static void initCacheManaer() {
|
||||||
|
cacheManager = new CacheManager();
|
||||||
|
cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
|
cacheManager.removalAll();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
private Ehcache getCache() {
|
private Ehcache getCache() {
|
||||||
ApplicationContext ctx = MockApplicationContext.getContext();
|
Ehcache cache = cacheManager.getCache("ehcacheusercachetests");
|
||||||
|
cache.removeAll();
|
||||||
|
|
||||||
return (Ehcache) ctx.getBean("eHCacheBackend");
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
private User getUser() {
|
private User getUser() {
|
||||||
@ -57,11 +64,8 @@ public class EhCacheBasedUserCacheTests extends TestCase {
|
|||||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
@Test
|
||||||
super.setUp();
|
public void cacheOperationsAreSuccessful() throws Exception {
|
||||||
}
|
|
||||||
|
|
||||||
public void testCacheOperation() throws Exception {
|
|
||||||
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
|
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
|
||||||
cache.setCache(getCache());
|
cache.setCache(getCache());
|
||||||
cache.afterPropertiesSet();
|
cache.afterPropertiesSet();
|
||||||
@ -79,15 +83,12 @@ public class EhCacheBasedUserCacheTests extends TestCase {
|
|||||||
assertNull(cache.getUserFromCache("UNKNOWN_USER"));
|
assertNull(cache.getUserFromCache("UNKNOWN_USER"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStartupDetectsMissingCache() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void startupDetectsMissingCache() throws Exception {
|
||||||
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
|
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
|
||||||
|
|
||||||
try {
|
|
||||||
cache.afterPropertiesSet();
|
cache.afterPropertiesSet();
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ehcache myCache = getCache();
|
Ehcache myCache = getCache();
|
||||||
cache.setCache(myCache);
|
cache.setCache(myCache);
|
||||||
|
@ -15,20 +15,23 @@
|
|||||||
|
|
||||||
package org.springframework.security.providers.x509.cache;
|
package org.springframework.security.providers.x509.cache;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
|
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.GrantedAuthorityImpl;
|
import org.springframework.security.GrantedAuthorityImpl;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
|
|
||||||
import org.springframework.security.providers.x509.X509TestUtils;
|
import org.springframework.security.providers.x509.X509TestUtils;
|
||||||
|
|
||||||
import org.springframework.security.userdetails.User;
|
import org.springframework.security.userdetails.User;
|
||||||
import org.springframework.security.userdetails.UserDetails;
|
import org.springframework.security.userdetails.UserDetails;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,22 +40,28 @@ import org.springframework.context.ApplicationContext;
|
|||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedX509UserCacheTests extends TestCase {
|
public class EhCacheBasedX509UserCacheTests {
|
||||||
//~ Constructors ===================================================================================================
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
public EhCacheBasedX509UserCacheTests() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EhCacheBasedX509UserCacheTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
private Ehcache getCache() {
|
@BeforeClass
|
||||||
ApplicationContext ctx = MockApplicationContext.getContext();
|
public static void initCacheManaer() {
|
||||||
|
cacheManager = new CacheManager();
|
||||||
|
cacheManager.addCache(new Cache("x509cachetests", 500, false, false, 30, 30));
|
||||||
|
}
|
||||||
|
|
||||||
return (Ehcache) ctx.getBean("eHCacheBackend");
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
|
cacheManager.removalAll();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Ehcache getCache() {
|
||||||
|
Ehcache cache = cacheManager.getCache("x509cachetests");
|
||||||
|
cache.removeAll();
|
||||||
|
|
||||||
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserDetails getUser() {
|
private UserDetails getUser() {
|
||||||
@ -60,11 +69,8 @@ public class EhCacheBasedX509UserCacheTests extends TestCase {
|
|||||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
@Test
|
||||||
super.setUp();
|
public void cacheOperationsAreSucessful() throws Exception {
|
||||||
}
|
|
||||||
|
|
||||||
public void testCacheOperation() throws Exception {
|
|
||||||
EhCacheBasedX509UserCache cache = new EhCacheBasedX509UserCache();
|
EhCacheBasedX509UserCache cache = new EhCacheBasedX509UserCache();
|
||||||
cache.setCache(getCache());
|
cache.setCache(getCache());
|
||||||
cache.afterPropertiesSet();
|
cache.afterPropertiesSet();
|
||||||
|
@ -15,27 +15,26 @@
|
|||||||
|
|
||||||
package org.springframework.security.util;
|
package org.springframework.security.util;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.security.ConfigAttribute;
|
import org.springframework.security.ConfigAttribute;
|
||||||
import org.springframework.security.ConfigAttributeDefinition;
|
import org.springframework.security.ConfigAttributeDefinition;
|
||||||
import org.springframework.security.MockApplicationContext;
|
|
||||||
import org.springframework.security.MockFilterConfig;
|
import org.springframework.security.MockFilterConfig;
|
||||||
import org.springframework.security.context.HttpSessionContextIntegrationFilter;
|
import org.springframework.security.context.HttpSessionContextIntegrationFilter;
|
||||||
import org.springframework.security.intercept.web.MockFilterInvocationDefinitionSource;
|
import org.springframework.security.intercept.web.MockFilterInvocationDefinitionSource;
|
||||||
import org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource;
|
import org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource;
|
||||||
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
|
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
import org.springframework.context.support.StaticApplicationContext;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FilterChainProxy}.
|
* Tests {@link FilterChainProxy}.
|
||||||
@ -64,7 +63,7 @@ public class FilterChainProxyTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testDetectsFilterInvocationDefinitionSourceThatDoesNotReturnAllConfigAttributes() throws Exception {
|
public void testDetectsFilterInvocationDefinitionSourceThatDoesNotReturnAllConfigAttributes() throws Exception {
|
||||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||||
filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
|
filterChainProxy.setApplicationContext(new StaticApplicationContext());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
filterChainProxy.setFilterInvocationDefinitionSource(new MockFilterInvocationDefinitionSource(false, false));
|
filterChainProxy.setFilterInvocationDefinitionSource(new MockFilterInvocationDefinitionSource(false, false));
|
||||||
@ -77,7 +76,7 @@ public class FilterChainProxyTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testDetectsIfConfigAttributeDoesNotReturnValueForGetAttributeMethod() throws Exception {
|
public void testDetectsIfConfigAttributeDoesNotReturnValueForGetAttributeMethod() throws Exception {
|
||||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||||
filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
|
filterChainProxy.setApplicationContext(new StaticApplicationContext());
|
||||||
|
|
||||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new MockConfigAttribute());
|
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new MockConfigAttribute());
|
||||||
|
|
||||||
@ -95,16 +94,12 @@ public class FilterChainProxyTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testDetectsMissingFilterInvocationDefinitionSource() throws Exception {
|
public void testDetectsMissingFilterInvocationDefinitionSource() throws Exception {
|
||||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||||
filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
|
filterChainProxy.setApplicationContext(new StaticApplicationContext());
|
||||||
|
|
||||||
try {
|
|
||||||
filterChainProxy.afterPropertiesSet();
|
filterChainProxy.afterPropertiesSet();
|
||||||
fail("Should have thrown IllegalArgumentException");
|
|
||||||
} catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
|
||||||
<!--
|
|
||||||
* Copyright 2004 Acegi Technology Pty Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
-->
|
|
||||||
|
|
||||||
<beans>
|
|
||||||
|
|
||||||
<!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider -->
|
|
||||||
<bean id="authenticationLoggerListener" class="org.springframework.security.event.authentication.LoggerListener"/>
|
|
||||||
|
|
||||||
<!-- Automatically receives AuthenticationEvent messages from AbstractSecurityInterceptor -->
|
|
||||||
<bean id="secureObjectLoggerListener" class="org.springframework.security.event.authorization.LoggerListener"/>
|
|
||||||
|
|
||||||
<!-- Setup a cache we can use in tests of the caching layer -->
|
|
||||||
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
|
|
||||||
<property name="configLocation" value="classpath:/ehcache-failsafe.xml"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="eHCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
|
|
||||||
<property name="cacheManager">
|
|
||||||
<ref local="cacheManager"/>
|
|
||||||
</property>
|
|
||||||
<property name="cacheName" value="testingCache"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
|
2
pom.xml
2
pom.xml
@ -602,7 +602,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.2.9</version>
|
<version>1.2.13</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sf.ehcache</groupId>
|
<groupId>net.sf.ehcache</groupId>
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
<version>1.2.4</version>
|
<version>1.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -16,57 +16,48 @@
|
|||||||
|
|
||||||
package org.springframework.security.providers.portlet.cache;
|
package org.springframework.security.providers.portlet.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Cache;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
|
||||||
import org.springframework.security.providers.portlet.PortletTestUtils;
|
import org.springframework.security.providers.portlet.PortletTestUtils;
|
||||||
import org.springframework.cache.ehcache.EhCacheFactoryBean;
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EhCacheBasedPortletUserCache}.
|
* Tests for {@link EhCacheBasedUserCache}.
|
||||||
*
|
*
|
||||||
* @author John A. Lewis
|
* @author John A. Lewis
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedUserCacheTests extends TestCase {
|
public class EhCacheBasedUserCacheTests {
|
||||||
|
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
private static EhCacheFactoryBean cacheFactory;
|
private static CacheManager cacheManager;
|
||||||
|
|
||||||
static {
|
@BeforeClass
|
||||||
cacheFactory = new EhCacheFactoryBean();
|
public static void initCacheManaer() {
|
||||||
cacheFactory.setCacheName("portletUserCache");
|
cacheManager = new CacheManager();
|
||||||
try {
|
cacheManager.addCache(new Cache("portletusercachetests", 500, false, false, 30, 30));
|
||||||
cacheFactory.afterPropertiesSet();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("unable to initialize cache factory", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Constructors ===================================================================================================
|
@AfterClass
|
||||||
|
public static void shutdownCacheManager() {
|
||||||
public EhCacheBasedUserCacheTests() {
|
cacheManager.removalAll();
|
||||||
super();
|
cacheManager.shutdown();
|
||||||
}
|
|
||||||
|
|
||||||
public EhCacheBasedUserCacheTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache getCache() {
|
private Cache getCache() {
|
||||||
return (Cache)cacheFactory.getObject();
|
Cache cache = cacheManager.getCache("portletusercachetests");
|
||||||
|
cache.removeAll();
|
||||||
|
|
||||||
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCacheOperation() throws Exception {
|
public void testCacheOperation() throws Exception {
|
||||||
|
|
||||||
// Create the cache
|
// Create the cache
|
||||||
@ -76,8 +67,7 @@ public class EhCacheBasedUserCacheTests extends TestCase {
|
|||||||
|
|
||||||
// Check it gets stored in the cache
|
// Check it gets stored in the cache
|
||||||
cache.putUserInCache(PortletTestUtils.createUser());
|
cache.putUserInCache(PortletTestUtils.createUser());
|
||||||
assertEquals(PortletTestUtils.TESTCRED,
|
assertEquals(PortletTestUtils.TESTCRED, cache.getUserFromCache(PortletTestUtils.TESTUSER).getPassword());
|
||||||
cache.getUserFromCache(PortletTestUtils.TESTUSER).getPassword());
|
|
||||||
|
|
||||||
// Check it gets removed from the cache
|
// Check it gets removed from the cache
|
||||||
cache.removeUserFromCache(PortletTestUtils.TESTUSER);
|
cache.removeUserFromCache(PortletTestUtils.TESTUSER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user