diff --git a/core/src/main/java/org/springframework/security/config/LdapUserServiceBeanDefinitionParser.java b/core/src/main/java/org/springframework/security/config/LdapUserServiceBeanDefinitionParser.java
index d85dbc9918..1673f8d63b 100644
--- a/core/src/main/java/org/springframework/security/config/LdapUserServiceBeanDefinitionParser.java
+++ b/core/src/main/java/org/springframework/security/config/LdapUserServiceBeanDefinitionParser.java
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
-import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
diff --git a/core/src/test/java/org/springframework/security/PopulatedDatabase.java b/core/src/test/java/org/springframework/security/PopulatedDatabase.java
index 1ddaaf836a..19feb52c84 100644
--- a/core/src/test/java/org/springframework/security/PopulatedDatabase.java
+++ b/core/src/test/java/org/springframework/security/PopulatedDatabase.java
@@ -16,7 +16,6 @@
package org.springframework.security;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@@ -30,7 +29,7 @@ import javax.sql.DataSource;
public class PopulatedDatabase {
//~ Static fields/initializers =====================================================================================
- private static DriverManagerDataSource dataSource = null;
+ private static TestDataSource dataSource = null;
//~ Constructors ===================================================================================================
@@ -47,12 +46,7 @@ public class PopulatedDatabase {
}
private static void setupDataSource() {
- dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
- dataSource.setUrl("jdbc:hsqldb:mem:springsecuritytest");
- dataSource.setUsername("sa");
- dataSource.setPassword("");
-
+ dataSource = new TestDataSource("springsecuritytest");
JdbcTemplate template = new JdbcTemplate(dataSource);
template.execute(
diff --git a/core/src/test/java/org/springframework/security/TestDataSource.java b/core/src/test/java/org/springframework/security/TestDataSource.java
new file mode 100644
index 0000000000..7284a7fbb2
--- /dev/null
+++ b/core/src/test/java/org/springframework/security/TestDataSource.java
@@ -0,0 +1,29 @@
+package org.springframework.security;
+
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.beans.factory.DisposableBean;
+
+/**
+ * A Datasource bean which starts an in-memory HSQL database with the supplied name and
+ * shuts down the database when the application context it is defined in is closed.
+ *
+ * @author Luke Taylor
+ * @version $Id$
+ */
+public class TestDataSource extends DriverManagerDataSource implements DisposableBean {
+ String name;
+
+ public TestDataSource(String databaseName) {
+ name = databaseName;
+ setDriverClassName("org.hsqldb.jdbcDriver");
+ setUrl("jdbc:hsqldb:mem:" + databaseName);
+ setUsername("sa");
+ setPassword("");
+ }
+
+ public void destroy() throws Exception {
+ System.out.println("Shutting down database: " + name);
+ new JdbcTemplate(this).execute("SHUTDOWN");
+ }
+}
diff --git a/core/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java b/core/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java
index a673f572f4..b05fdf0a5e 100644
--- a/core/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java
+++ b/core/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java
@@ -9,14 +9,16 @@ import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.AfterClass;
+
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.MockApplicationContext;
+import org.springframework.security.TestDataSource;
import org.springframework.security.acls.AuditableAccessControlEntry;
import org.springframework.security.acls.MutableAcl;
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
@@ -38,13 +40,13 @@ public class BasicLookupStrategyTests {
private LookupStrategy strategy;
- private static DriverManagerDataSource dataSource;
+ private static TestDataSource dataSource;
//~ Methods ========================================================================================================
@BeforeClass
public static void createDatabase() throws Exception {
- dataSource = new DriverManagerDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:lookupstrategytest", "sa", "");
+ dataSource = new TestDataSource("lookupstrategytest");
jdbcTemplate = new JdbcTemplate(dataSource);
Resource resource = new ClassPathResource("org/springframework/security/acls/jdbc/testData.sql");
@@ -52,6 +54,11 @@ public class BasicLookupStrategyTests {
jdbcTemplate.execute(sql);
}
+ @AfterClass
+ public static void dropDatabase() throws Exception {
+ dataSource.destroy();
+ }
+
@Before
public void populateDatabase() {
String query = "INSERT INTO acl_sid(ID,PRINCIPAL,SID) VALUES (1,1,'ben');"
diff --git a/core/src/test/java/org/springframework/security/config/DataSourcePopulator.java b/core/src/test/java/org/springframework/security/config/DataSourcePopulator.java
index a18b4c466e..4f0a372c4b 100644
--- a/core/src/test/java/org/springframework/security/config/DataSourcePopulator.java
+++ b/core/src/test/java/org/springframework/security/config/DataSourcePopulator.java
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
* @author Ben Alex
* @version $Id: DataSourcePopulator.java 2291 2007-12-03 02:56:52Z benalex $
*/
-public class DataSourcePopulator implements InitializingBean, DisposableBean {
+public class DataSourcePopulator implements InitializingBean {
//~ Instance fields ================================================================================================
JdbcTemplate template;
@@ -71,9 +71,4 @@ public class DataSourcePopulator implements InitializingBean, DisposableBean {
public void setDataSource(DataSource dataSource) {
this.template = new JdbcTemplate(dataSource);
}
-
- public void destroy() throws Exception {
- template.execute("DROP TABLE AUTHORITIES");
- template.execute("DROP TABLE USERS");
- }
}
diff --git a/core/src/test/java/org/springframework/security/config/JdbcUserServiceBeanDefinitionParserTests.java b/core/src/test/java/org/springframework/security/config/JdbcUserServiceBeanDefinitionParserTests.java
index 752654f3a4..35dbc40224 100644
--- a/core/src/test/java/org/springframework/security/config/JdbcUserServiceBeanDefinitionParserTests.java
+++ b/core/src/test/java/org/springframework/security/config/JdbcUserServiceBeanDefinitionParserTests.java
@@ -10,6 +10,8 @@ import org.springframework.security.util.InMemoryXmlApplicationContext;
import org.springframework.security.AuthenticationManager;
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
+import javax.sql.DataSource;
+
/**
* @author Ben Alex
* @author Luke Taylor
@@ -22,11 +24,9 @@ public class JdbcUserServiceBeanDefinitionParserTests {
" " +
" " +
" " +
- " " +
- " " +
- " " +
- " " +
- " " +
+
+ " " +
+ " " +
" ";
@After
diff --git a/core/src/test/java/org/springframework/security/providers/ldap/LdapAuthenticationProviderTests.java b/core/src/test/java/org/springframework/security/providers/ldap/LdapAuthenticationProviderTests.java
index c4288ff50b..18d3e76858 100644
--- a/core/src/test/java/org/springframework/security/providers/ldap/LdapAuthenticationProviderTests.java
+++ b/core/src/test/java/org/springframework/security/providers/ldap/LdapAuthenticationProviderTests.java
@@ -89,8 +89,8 @@ public class LdapAuthenticationProviderTests extends TestCase {
}
public void testNormalUsage() {
- LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
- new MockAuthoritiesPopulator());
+ MockAuthoritiesPopulator populator = new MockAuthoritiesPopulator();
+ LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(), populator);
LdapUserDetailsMapper userMapper = new LdapUserDetailsMapper();
userMapper.setRoleAttributes(new String[] {"ou"});
ldapProvider.setUserDetailsContextMapper(userMapper);
@@ -104,6 +104,7 @@ public class LdapAuthenticationProviderTests extends TestCase {
assertEquals(2, user.getAuthorities().length);
assertEquals("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=", user.getPassword());
assertEquals("ben", user.getUsername());
+ assertEquals("ben", populator.getRequestedUsername());
ArrayList authorities = new ArrayList();
authorities.add(user.getAuthorities()[0].getAuthority());
@@ -162,8 +163,15 @@ public class LdapAuthenticationProviderTests extends TestCase {
}
class MockAuthoritiesPopulator implements LdapAuthoritiesPopulator {
+ String username;
+
public GrantedAuthority[] getGrantedAuthorities(DirContextOperations userCtx, String username) {
+ this.username = username;
return new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_FROM_POPULATOR")};
}
+
+ String getRequestedUsername() {
+ return username;
+ }
}
}
diff --git a/core/src/test/java/org/springframework/security/ui/rememberme/JdbcTokenRepositoryImplTests.java b/core/src/test/java/org/springframework/security/ui/rememberme/JdbcTokenRepositoryImplTests.java
index 6da2a02ef5..877fc864db 100644
--- a/core/src/test/java/org/springframework/security/ui/rememberme/JdbcTokenRepositoryImplTests.java
+++ b/core/src/test/java/org/springframework/security/ui/rememberme/JdbcTokenRepositoryImplTests.java
@@ -1,7 +1,7 @@
package org.springframework.security.ui.rememberme;
+import org.springframework.security.TestDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.junit.After;
import org.junit.AfterClass;
@@ -20,17 +20,18 @@ import java.util.Map;
* @version $Id$
*/
public class JdbcTokenRepositoryImplTests {
- private static DriverManagerDataSource dataSource;
+ private static TestDataSource dataSource;
private JdbcTokenRepositoryImpl repo;
private JdbcTemplate template;
@BeforeClass
public static void createDataSource() {
- dataSource = new DriverManagerDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:tokenrepotest", "sa", "");
+ dataSource = new TestDataSource("tokenrepotest");
}
@AfterClass
- public static void clearDataSource() {
+ public static void clearDataSource() throws Exception {
+ dataSource.destroy();
dataSource = null;
}
diff --git a/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcUserDetailsManagerTests.java b/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcUserDetailsManagerTests.java
index c5f5025be1..e06a36f156 100644
--- a/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcUserDetailsManagerTests.java
+++ b/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcUserDetailsManagerTests.java
@@ -7,6 +7,7 @@ import org.springframework.security.MockAuthenticationManager;
import org.springframework.security.PopulatedDatabase;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
+import org.springframework.security.TestDataSource;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
import org.springframework.security.providers.dao.UserCache;
@@ -14,7 +15,6 @@ import org.springframework.security.userdetails.User;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.util.AuthorityUtils;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.junit.After;
import org.junit.AfterClass;
@@ -43,18 +43,19 @@ public class JdbcUserDetailsManagerTests {
private static final UserDetails joe = new User("joe", "password", true, true, true, true,
AuthorityUtils.stringArrayToAuthorityArray(new String[]{"A","C","B"}));
- private static DriverManagerDataSource dataSource;
+ private static TestDataSource dataSource;
private JdbcUserDetailsManager manager;
private MockUserCache cache;
private JdbcTemplate template;
@BeforeClass
public static void createDataSource() {
- dataSource = new DriverManagerDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:jdbcusermgrtest", "sa", "");
+ dataSource = new TestDataSource("jdbcusermgrtest");
}
@AfterClass
- public static void clearDataSource() {
+ public static void clearDataSource() throws Exception {
+ dataSource.destroy();
dataSource = null;
}
diff --git a/core/src/test/resources/org/springframework/security/acls/jdbc/applicationContext-test.xml b/core/src/test/resources/org/springframework/security/acls/jdbc/applicationContext-test.xml
index 3d18741df7..d67d873013 100644
--- a/core/src/test/resources/org/springframework/security/acls/jdbc/applicationContext-test.xml
+++ b/core/src/test/resources/org/springframework/security/acls/jdbc/applicationContext-test.xml
@@ -64,20 +64,8 @@
-
-
- org.hsqldb.jdbcDriver
-
-
- jdbc:hsqldb:mem:test
-
-
-
- sa
-
-
-
-
+
+