diff --git a/.classpath b/.classpath
index 8bd5d18703..13063b1cba 100644
--- a/.classpath
+++ b/.classpath
@@ -20,5 +20,6 @@
AccessDecisionManager
is able to
* process authorization requests presented with the passed
* ConfigAttribute
.
- *
+ *
*
* This allows the AbstractSecurityInterceptor
to check every
* configuration attribute can be consumed by the configured
diff --git a/core/src/main/java/org/acegisecurity/providers/dao/MD5PasswordEncoder.java b/core/src/main/java/org/acegisecurity/providers/dao/MD5PasswordEncoder.java
index e51f359efd..4eb4745191 100644
--- a/core/src/main/java/org/acegisecurity/providers/dao/MD5PasswordEncoder.java
+++ b/core/src/main/java/org/acegisecurity/providers/dao/MD5PasswordEncoder.java
@@ -20,9 +20,15 @@ import org.apache.commons.codec.digest.DigestUtils;
/**
*
- * MD5 implementation of PasswordEncoder.
The ignorePasswordCase parameter is not used for this implementation.
A null password is encoded to the same value as an empty ("") password.
+ * MD5 implementation of PasswordEncoder.
+ *
+ * The ignorePasswordCase parameter is not used for this implementation. + *
+ * + *+ * A null password is encoded to the same value as an empty ("") password. *
* * @author colin sampaleanu diff --git a/core/src/main/java/org/acegisecurity/providers/dao/SHAPasswordEncoder.java b/core/src/main/java/org/acegisecurity/providers/dao/SHAPasswordEncoder.java index 9b830b0904..19695ee9eb 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/SHAPasswordEncoder.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/SHAPasswordEncoder.java @@ -20,9 +20,15 @@ import org.apache.commons.codec.digest.DigestUtils; /** *
- * SHA implementation of PasswordEncoder.
The ignorePasswordCase parameter is not used for this implementation.
A null password is encoded to the same value as an empty ("") password.
+ * SHA implementation of PasswordEncoder.
+ *
+ * The ignorePasswordCase parameter is not used for this implementation. + *
+ * + *+ * A null password is encoded to the same value as an empty ("") password. *
* * @author colin sampaleanu diff --git a/core/src/main/java/org/acegisecurity/userdetails/jdbc/JdbcDaoImpl.java b/core/src/main/java/org/acegisecurity/userdetails/jdbc/JdbcDaoImpl.java index 922980296c..b078473dcb 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/jdbc/JdbcDaoImpl.java +++ b/core/src/main/java/org/acegisecurity/userdetails/jdbc/JdbcDaoImpl.java @@ -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; diff --git a/core/src/test/java/org/acegisecurity/providers/dao/jdbc/JdbcDaoTests.java b/core/src/test/java/org/acegisecurity/providers/dao/jdbc/JdbcDaoTests.java index b8790f4563..7bf595a02f 100644 --- a/core/src/test/java/org/acegisecurity/providers/dao/jdbc/JdbcDaoTests.java +++ b/core/src/test/java/org/acegisecurity/providers/dao/jdbc/JdbcDaoTests.java @@ -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; + } } diff --git a/test/.cvsignore b/test/.cvsignore index 91696b3e12..e69de29bb2 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -1,2 +0,0 @@ -acegisecuritytest.properties -acegisecuritytest.script diff --git a/test/acegisecuritytest.properties b/test/acegisecuritytest.properties new file mode 100644 index 0000000000..1a667a021a --- /dev/null +++ b/test/acegisecuritytest.properties @@ -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 diff --git a/test/acegisecuritytest.script b/test/acegisecuritytest.script new file mode 100644 index 0000000000..c116c43e60 --- /dev/null +++ b/test/acegisecuritytest.script @@ -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')