SEC-670: Provide mutator for JdbcMutableAclService.foreignKeysInDatabase property.

This commit is contained in:
Ben Alex 2008-04-05 22:57:02 +00:00
parent 8a7bfafce9
commit 54882fe1ea
2 changed files with 12 additions and 2 deletions

View File

@ -60,7 +60,7 @@ import javax.sql.DataSource;
public class JdbcMutableAclService extends JdbcAclService implements MutableAclService {
//~ Instance fields ================================================================================================
private boolean foreignKeysInDatabase = false;
private boolean foreignKeysInDatabase = true;
private AclCache aclCache;
private String deleteClassByClassNameString = "DELETE FROM acl_class WHERE class=?";
private String deleteEntryByObjectIdentityForeignKey = "DELETE FROM acl_entry WHERE acl_object_identity=?";
@ -385,5 +385,12 @@ public class JdbcMutableAclService extends JdbcAclService implements MutableAclS
Assert.hasText(identityQuery, "New identity query is required");
this.identityQuery = identityQuery;
}
/**
* @param foreignKeysInDatabase if false this class will perform additional FK constrain checking, which may
* cause deadlocks (the default is true, so deadlocks are avoided but the database is expected to enforce FKs)
*/
public void setForeignKeysInDatabase(boolean foreignKeysInDatabase) {
this.foreignKeysInDatabase = foreignKeysInDatabase;
}
}

View File

@ -318,11 +318,14 @@ public class JdbcAclServiceTests extends AbstractTransactionalDataSourceSpringCo
public void testDeleteAclWithChildrenThrowsException() throws Exception {
try {
ObjectIdentity topParentOid = new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(100));
jdbcMutableAclService.setForeignKeysInDatabase(false); // switch on FK checking in the class, not database
jdbcMutableAclService.deleteAcl(topParentOid, false);
fail("It should have thrown ChildrenExistException");
}
catch (ChildrenExistException expected) {
assertTrue(true);
} finally {
jdbcMutableAclService.setForeignKeysInDatabase(true); // restore to the default
}
}