From d0a308c99bde8ede75d37b60454fdd4d4b8aff90 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Mon, 27 Apr 2009 10:21:31 +0000 Subject: [PATCH] SEC-1107: Added test to attempt to reproduce issue. --- .../security/acls/jdbc/JdbcAclService.java | 3 +-- .../acls/jdbc/JdbcMutableAclService.java | 3 +-- .../security/acls/jdbc/DatabaseSeeder.java | 2 +- ...s.java => JdbcMutableAclServiceTests.java} | 20 +++++++++++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) rename acl/src/test/java/org/springframework/security/acls/jdbc/{JdbcAclServiceTests.java => JdbcMutableAclServiceTests.java} (95%) diff --git a/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcAclService.java b/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcAclService.java index 77e3bab9a3..07ec24cb9d 100644 --- a/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcAclService.java +++ b/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcAclService.java @@ -75,8 +75,7 @@ public class JdbcAclService implements AclService { Object[] args = {parentIdentity.getIdentifier(), parentIdentity.getJavaType().getName()}; List objects = jdbcTemplate.query(selectAclObjectWithParent, args, new RowMapper() { - public ObjectIdentity mapRow(ResultSet rs, int rowNum) - throws SQLException { + public ObjectIdentity mapRow(ResultSet rs, int rowNum) throws SQLException { String javaType = rs.getString("class"); Long identifier = new Long(rs.getLong("obj_id")); diff --git a/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcMutableAclService.java b/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcMutableAclService.java index 8e3d6836a2..2cc3ab0909 100644 --- a/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcMutableAclService.java +++ b/acl/src/main/java/org/springframework/security/acls/jdbc/JdbcMutableAclService.java @@ -143,8 +143,7 @@ public class JdbcMutableAclService extends JdbcAclService implements MutableAclS protected void createObjectIdentity(ObjectIdentity object, Sid owner) { Long sidId = createOrRetrieveSidPrimaryKey(owner, true); Long classId = createOrRetrieveClassPrimaryKey(object.getJavaType(), true); - jdbcTemplate.update(insertObjectIdentity, - new Object[] {classId, object.getIdentifier().toString(), sidId, new Boolean(true)}); + jdbcTemplate.update(insertObjectIdentity, classId, object.getIdentifier().toString(), sidId, Boolean.TRUE); } /** diff --git a/acl/src/test/java/org/springframework/security/acls/jdbc/DatabaseSeeder.java b/acl/src/test/java/org/springframework/security/acls/jdbc/DatabaseSeeder.java index c70e56096a..f261d6bd64 100644 --- a/acl/src/test/java/org/springframework/security/acls/jdbc/DatabaseSeeder.java +++ b/acl/src/test/java/org/springframework/security/acls/jdbc/DatabaseSeeder.java @@ -27,7 +27,7 @@ import javax.sql.DataSource; /** - * Seeds the database for {@link JdbcAclServiceTests}. + * Seeds the database for {@link JdbcMutableAclServiceTests}. * * @author Ben Alex * @version $Id$ diff --git a/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java b/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcMutableAclServiceTests.java similarity index 95% rename from acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java rename to acl/src/test/java/org/springframework/security/acls/jdbc/JdbcMutableAclServiceTests.java index 5430c7ffc6..3c8d6770b6 100644 --- a/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java +++ b/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcMutableAclServiceTests.java @@ -54,10 +54,10 @@ import org.springframework.transaction.annotation.Transactional; * * @author Ben Alex * @author Andrei Stefan - * @version $Id:JdbcAclServiceTests.java 1754 2006-11-17 02:01:21Z benalex $ + * @version $Id:JdbcMutableAclServiceTests.java 1754 2006-11-17 02:01:21Z benalex $ */ @ContextConfiguration(locations={"/org/springframework/security/acls/jdbc/applicationContext-test.xml"}) -public class JdbcAclServiceTests extends AbstractTransactionalJUnit4SpringContextTests { +public class JdbcMutableAclServiceTests extends AbstractTransactionalJUnit4SpringContextTests { //~ Constant fields ================================================================================================ private final Authentication auth = new TestingAuthenticationToken("ben", "ignored","ROLE_ADMINISTRATOR"); @@ -275,7 +275,7 @@ public class JdbcAclServiceTests extends AbstractTransactionalJUnit4SpringContex } @Test - public void testConstructorRejectsNullParameters() throws Exception { + public void constructorRejectsNullParameters() throws Exception { try { new JdbcMutableAclService(null, lookupStrategy, aclCache); fail("It should have thrown IllegalArgumentException"); @@ -299,7 +299,7 @@ public class JdbcAclServiceTests extends AbstractTransactionalJUnit4SpringContex } @Test - public void testCreateAclRejectsNullParameter() throws Exception { + public void createAclRejectsNullParameter() throws Exception { try { jdbcMutableAclService.createAcl(null); fail("It should have thrown IllegalArgumentException"); @@ -379,6 +379,18 @@ public class JdbcAclServiceTests extends AbstractTransactionalJUnit4SpringContex assertNull(aclCache.getFromCache(new Long(102))); } + /** SEC-1107 */ + @Test + @Transactional + @Rollback + public void identityWithIntegerIdIsSupported() throws Exception { + SecurityContextHolder.getContext().setAuthentication(auth); + ObjectIdentity oid = new ObjectIdentityImpl("org.springframework.security.TargetObject", Integer.valueOf(101)); + jdbcMutableAclService.createAcl(oid); + + assertNotNull(jdbcMutableAclService.readAclById(new ObjectIdentityImpl("org.springframework.security.TargetObject", Long.valueOf(101)))); + } + /** * SEC-655 */