add back HSQL db in test dir, as it turns out _it is_ supposed to be in CVS

modify JdbcDaoTests to test for role prefix functionality
fix glitch in JdbcDaoImpl
modify Eclipse classpath so HSQL lib is loaded, so unit tests can run in Eclipse as well.
This commit is contained in:
Colin Sampaleanu
2004-04-15 03:34:18 +00:00
parent 18d5c59532
commit 41a837f8cd
9 changed files with 150 additions and 12 deletions

View File

@@ -15,7 +15,6 @@
package net.sf.acegisecurity;
/**
* Makes a final access control (authorization) decision.
*
@@ -42,7 +41,7 @@ public interface AccessDecisionManager {
* Indicates whether this <code>AccessDecisionManager</code> is able to
* process authorization requests presented with the passed
* <code>ConfigAttribute</code>.
*
*
* <p>
* This allows the <code>AbstractSecurityInterceptor</code> to check every
* configuration attribute can be consumed by the configured

View File

@@ -20,9 +20,15 @@ import org.apache.commons.codec.digest.DigestUtils;
/**
* <p>
* MD5 implementation of PasswordEncoder.<br/
* > The ignorePasswordCase parameter is not used for this implementation.<br/
* > A null password is encoded to the same value as an empty ("") password.
* MD5 implementation of PasswordEncoder.
* </p>
*
* <p>
* The ignorePasswordCase parameter is not used for this implementation.
* </p>
*
* <p>
* A null password is encoded to the same value as an empty ("") password.
* </p>
*
* @author colin sampaleanu

View File

@@ -20,9 +20,15 @@ import org.apache.commons.codec.digest.DigestUtils;
/**
* <p>
* SHA implementation of PasswordEncoder.<br/
* > The ignorePasswordCase parameter is not used for this implementation.<br/
* > A null password is encoded to the same value as an empty ("") password.
* SHA implementation of PasswordEncoder.
* </p>
*
* <p>
* The ignorePasswordCase parameter is not used for this implementation.
* </p>
*
* <p>
* A null password is encoded to the same value as an empty ("") password.
* </p>
*
* @author colin sampaleanu

View File

@@ -74,7 +74,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements AuthenticationDao {
private MappingSqlQuery authoritiesByUsernameMapping;
private MappingSqlQuery usersByUsernameMapping;
private String authoritiesByUsernameQuery;
private String rolePrefix = "ROLE_";
private String rolePrefix = "";
private String usersByUsernameQuery;
//~ Constructors ===========================================================
@@ -212,7 +212,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements AuthenticationDao {
protected Object mapRow(ResultSet rs, int rownum)
throws SQLException {
String roleName = rolePrefix + rs.getString(1);
String roleName = rolePrefix + rs.getString(2);
GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);
return authority;

View File

@@ -105,6 +105,17 @@ public class JdbcDaoTests extends TestCase {
assertEquals("wombat", dao.loadUserByUsername("ScOTt").getPassword());
}
public void testRolePrefixWorks() throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDaoWithRolePrefix();
User user = dao.loadUserByUsername("marissa");
assertEquals("marissa", user.getUsername());
assertEquals("ARBITRARY_PREFIX_ROLE_TELLER",
user.getAuthorities()[0].getAuthority());
assertEquals("ARBITRARY_PREFIX_ROLE_SUPERVISOR",
user.getAuthorities()[1].getAuthority());
assertEquals(2, user.getAuthorities().length);
}
public void testStartupFailsIfDataSourceNotSet() throws Exception {
JdbcDaoImpl dao = new JdbcDaoImpl();
@@ -141,4 +152,20 @@ public class JdbcDaoTests extends TestCase {
return dao;
}
private JdbcDaoImpl makePopulatedJdbcDaoWithRolePrefix()
throws Exception {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("org.hsqldb.jdbcDriver");
ds.setUrl("jdbc:hsqldb:acegisecuritytest");
ds.setUsername("sa");
ds.setPassword("");
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setDataSource(ds);
dao.setRolePrefix("ARBITRARY_PREFIX_");
dao.afterPropertiesSet();
return dao;
}
}