Selaa lähdekoodia

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

Ben Alex 17 vuotta sitten
vanhempi
commit
54882fe1ea

+ 9 - 2
acl/src/main/java/org/springframework/security/acls/jdbc/JdbcMutableAclService.java

@@ -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;
+	}
 }

+ 3 - 0
acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java

@@ -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
         }
     }