Search in sources :

Example 1 with ChildrenExistException

use of org.springframework.security.acls.model.ChildrenExistException in project spring-security by spring-projects.

the class JdbcMutableAclServiceTests method deleteAclWithChildrenThrowsException.

@Test
@Transactional
public void deleteAclWithChildrenThrowsException() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    MutableAcl parent = jdbcMutableAclService.createAcl(topParentOid);
    MutableAcl child = jdbcMutableAclService.createAcl(middleParentOid);
    // Specify the inheritance hierarchy
    child.setParent(parent);
    jdbcMutableAclService.updateAcl(child);
    try {
        // switch on FK
        jdbcMutableAclService.setForeignKeysInDatabase(false);
        // checking in the
        // class, not database
        jdbcMutableAclService.deleteAcl(topParentOid, false);
        fail("It should have thrown ChildrenExistException");
    } catch (ChildrenExistException expected) {
    } finally {
        // restore to the
        jdbcMutableAclService.setForeignKeysInDatabase(true);
    // default
    }
}
Also used : ChildrenExistException(org.springframework.security.acls.model.ChildrenExistException) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ChildrenExistException

use of org.springframework.security.acls.model.ChildrenExistException in project spring-security by spring-projects.

the class JdbcMutableAclService method deleteAcl.

public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    Assert.notNull(objectIdentity, "Object Identity required");
    Assert.notNull(objectIdentity.getIdentifier(), "Object Identity doesn't provide an identifier");
    if (deleteChildren) {
        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (children != null) {
            for (ObjectIdentity child : children) {
                deleteAcl(child, true);
            }
        }
    } else {
        if (!foreignKeysInDatabase) {
            // We need to perform a manual verification for what a FK would normally
            // do
            // We generally don't do this, in the interests of deadlock management
            List<ObjectIdentity> children = findChildren(objectIdentity);
            if (children != null) {
                throw new ChildrenExistException("Cannot delete '" + objectIdentity + "' (has " + children.size() + " children)");
            }
        }
    }
    Long oidPrimaryKey = retrieveObjectIdentityPrimaryKey(objectIdentity);
    // Delete this ACL's ACEs in the acl_entry table
    deleteEntries(oidPrimaryKey);
    // Delete this ACL's acl_object_identity row
    deleteObjectIdentity(oidPrimaryKey);
    // Clear the cache
    aclCache.evictFromCache(objectIdentity);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ChildrenExistException(org.springframework.security.acls.model.ChildrenExistException)

Aggregations

ChildrenExistException (org.springframework.security.acls.model.ChildrenExistException)2 Test (org.junit.Test)1 MutableAcl (org.springframework.security.acls.model.MutableAcl)1 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)1 Transactional (org.springframework.transaction.annotation.Transactional)1