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:
parent
18d5c59532
commit
41a837f8cd
|
@ -20,5 +20,6 @@
|
|||
<classpathentry kind="lib" path="integration-test/lib/httpunit.jar"/>
|
||||
<classpathentry kind="lib" path="lib/regexp/jakarta-oro.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jakarta-commons/commons-codec.jar"/>
|
||||
<classpathentry kind="lib" path="lib/hsqldb/hsqldb.jar"/>
|
||||
<classpathentry kind="output" path="target/eclipseclasses"/>
|
||||
</classpath>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
acegisecuritytest.properties
|
||||
acegisecuritytest.script
|
|
@ -0,0 +1,16 @@
|
|||
#HSQL database
|
||||
#Wed Apr 14 23:23:24 EDT 2004
|
||||
sql.strict_fk=true
|
||||
readonly=false
|
||||
sql.strong_fk=true
|
||||
hsqldb.version=1.7.1
|
||||
version=1.7.1
|
||||
hsqldb.cache_scale=14
|
||||
sql.compare_in_locale=false
|
||||
sql.month=true
|
||||
hsqldb.log_size=200
|
||||
modified=no
|
||||
hsqldb.cache_version=1.7.0
|
||||
hsqldb.original_version=1.7.1
|
||||
hsqldb.compatible_version=1.7.0
|
||||
sql.enforce_size=false
|
|
@ -0,0 +1,85 @@
|
|||
CREATE TABLE USERS(USERNAME VARCHAR_IGNORECASE(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR_IGNORECASE(50) NOT NULL,ENABLED BIT NOT NULL)
|
||||
CREATE TABLE AUTHORITIES(USERNAME VARCHAR_IGNORECASE(50) NOT NULL,AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL,CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME))
|
||||
CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY)
|
||||
GRANT ALL ON CLASS "org.hsqldb.Library" TO PUBLIC
|
||||
GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC
|
||||
CREATE USER SA PASSWORD "" ADMIN
|
||||
SET IGNORECASE TRUE
|
||||
CREATE ALIAS DAYNAME FOR "org.hsqldb.Library.dayname"
|
||||
CREATE ALIAS SPACE FOR "org.hsqldb.Library.space"
|
||||
CREATE ALIAS SUBSTRING FOR "org.hsqldb.Library.substring"
|
||||
CREATE ALIAS HEXTORAW FOR "org.hsqldb.Library.hexToRaw"
|
||||
CREATE ALIAS SQRT FOR "java.lang.Math.sqrt"
|
||||
CREATE ALIAS ABS FOR "org.hsqldb.Library.abs"
|
||||
CREATE ALIAS POWER FOR "java.lang.Math.pow"
|
||||
CREATE ALIAS CHAR FOR "org.hsqldb.Library.character"
|
||||
CREATE ALIAS CONCAT FOR "org.hsqldb.Library.concat"
|
||||
CREATE ALIAS PI FOR "org.hsqldb.Library.pi"
|
||||
CREATE ALIAS RAWTOHEX FOR "org.hsqldb.Library.rawToHex"
|
||||
CREATE ALIAS SECOND FOR "org.hsqldb.Library.second"
|
||||
CREATE ALIAS TRUNCATE FOR "org.hsqldb.Library.truncate"
|
||||
CREATE ALIAS MONTH FOR "org.hsqldb.Library.month"
|
||||
CREATE ALIAS LOWER FOR "org.hsqldb.Library.lcase"
|
||||
CREATE ALIAS ATAN2 FOR "java.lang.Math.atan2"
|
||||
CREATE ALIAS REPEAT FOR "org.hsqldb.Library.repeat"
|
||||
CREATE ALIAS DAYOFMONTH FOR "org.hsqldb.Library.dayofmonth"
|
||||
CREATE ALIAS TAN FOR "java.lang.Math.tan"
|
||||
CREATE ALIAS RADIANS FOR "java.lang.Math.toRadians"
|
||||
CREATE ALIAS FLOOR FOR "java.lang.Math.floor"
|
||||
CREATE ALIAS NOW FOR "org.hsqldb.Library.now"
|
||||
CREATE ALIAS ACOS FOR "java.lang.Math.acos"
|
||||
CREATE ALIAS DAYOFWEEK FOR "org.hsqldb.Library.dayofweek"
|
||||
CREATE ALIAS CEILING FOR "java.lang.Math.ceil"
|
||||
CREATE ALIAS DAYOFYEAR FOR "org.hsqldb.Library.dayofyear"
|
||||
CREATE ALIAS LCASE FOR "org.hsqldb.Library.lcase"
|
||||
CREATE ALIAS WEEK FOR "org.hsqldb.Library.week"
|
||||
CREATE ALIAS SOUNDEX FOR "org.hsqldb.Library.soundex"
|
||||
CREATE ALIAS ASIN FOR "java.lang.Math.asin"
|
||||
CREATE ALIAS LOCATE FOR "org.hsqldb.Library.locate"
|
||||
CREATE ALIAS EXP FOR "java.lang.Math.exp"
|
||||
CREATE ALIAS MONTHNAME FOR "org.hsqldb.Library.monthname"
|
||||
CREATE ALIAS YEAR FOR "org.hsqldb.Library.year"
|
||||
CREATE ALIAS LEFT FOR "org.hsqldb.Library.left"
|
||||
CREATE ALIAS ROUNDMAGIC FOR "org.hsqldb.Library.roundMagic"
|
||||
CREATE ALIAS BITOR FOR "org.hsqldb.Library.bitor"
|
||||
CREATE ALIAS LTRIM FOR "org.hsqldb.Library.ltrim"
|
||||
CREATE ALIAS COT FOR "org.hsqldb.Library.cot"
|
||||
CREATE ALIAS COS FOR "java.lang.Math.cos"
|
||||
CREATE ALIAS MOD FOR "org.hsqldb.Library.mod"
|
||||
CREATE ALIAS SIGN FOR "org.hsqldb.Library.sign"
|
||||
CREATE ALIAS DEGREES FOR "java.lang.Math.toDegrees"
|
||||
CREATE ALIAS LOG FOR "java.lang.Math.log"
|
||||
CREATE ALIAS SIN FOR "java.lang.Math.sin"
|
||||
CREATE ALIAS CURTIME FOR "org.hsqldb.Library.curtime"
|
||||
CREATE ALIAS DIFFERENCE FOR "org.hsqldb.Library.difference"
|
||||
CREATE ALIAS INSERT FOR "org.hsqldb.Library.insert"
|
||||
CREATE ALIAS SUBSTR FOR "org.hsqldb.Library.substring"
|
||||
CREATE ALIAS DATABASE FOR "org.hsqldb.Library.database"
|
||||
CREATE ALIAS MINUTE FOR "org.hsqldb.Library.minute"
|
||||
CREATE ALIAS HOUR FOR "org.hsqldb.Library.hour"
|
||||
CREATE ALIAS IDENTITY FOR "org.hsqldb.Library.identity"
|
||||
CREATE ALIAS QUARTER FOR "org.hsqldb.Library.quarter"
|
||||
CREATE ALIAS CURDATE FOR "org.hsqldb.Library.curdate"
|
||||
CREATE ALIAS BITAND FOR "org.hsqldb.Library.bitand"
|
||||
CREATE ALIAS USER FOR "org.hsqldb.Library.user"
|
||||
CREATE ALIAS UCASE FOR "org.hsqldb.Library.ucase"
|
||||
CREATE ALIAS RTRIM FOR "org.hsqldb.Library.rtrim"
|
||||
CREATE ALIAS LOG10 FOR "org.hsqldb.Library.log10"
|
||||
CREATE ALIAS RIGHT FOR "org.hsqldb.Library.right"
|
||||
CREATE ALIAS ATAN FOR "java.lang.Math.atan"
|
||||
CREATE ALIAS UPPER FOR "org.hsqldb.Library.ucase"
|
||||
CREATE ALIAS ASCII FOR "org.hsqldb.Library.ascii"
|
||||
CREATE ALIAS RAND FOR "java.lang.Math.random"
|
||||
CREATE ALIAS LENGTH FOR "org.hsqldb.Library.length"
|
||||
CREATE ALIAS ROUND FOR "org.hsqldb.Library.round"
|
||||
CREATE ALIAS REPLACE FOR "org.hsqldb.Library.replace"
|
||||
INSERT INTO USERS VALUES('cooper','kookaburra',true)
|
||||
INSERT INTO USERS VALUES('dianne','emu',true)
|
||||
INSERT INTO USERS VALUES('marissa','koala',true)
|
||||
INSERT INTO USERS VALUES('peter','opal',false)
|
||||
INSERT INTO USERS VALUES('scott','wombat',true)
|
||||
INSERT INTO AUTHORITIES VALUES('marissa','ROLE_TELLER')
|
||||
INSERT INTO AUTHORITIES VALUES('marissa','ROLE_SUPERVISOR')
|
||||
INSERT INTO AUTHORITIES VALUES('dianne','ROLE_TELLER')
|
||||
INSERT INTO AUTHORITIES VALUES('scott','ROLE_TELLER')
|
||||
INSERT INTO AUTHORITIES VALUES('peter','ROLE_TELLER')
|
Loading…
Reference in New Issue