Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ public void setOwner(Sid newOwner) {
@Override
public void setParent(@Nullable Acl newParent) {
this.aclAuthorizationStrategy.securityCheck(this, AclAuthorizationStrategy.CHANGE_GENERAL);
Assert.isTrue(newParent == null || !newParent.equals(this), "Cannot be the parent of yourself");
Acl parent = newParent;
while (parent != null) {
Assert.isTrue(parent != this, "Cannot create a circular parent relationship");
parent = parent.getParentAcl();
}
this.parentAcl = newParent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,33 @@ public void gettersAndSettersAreConsistent() {
assertThat(new PrincipalSid("ben")).isEqualTo(acl.getOwner());
}

@Test
public void setParentRejectsAncestor() {
MutableAcl parentAcl = new AclImpl(new ObjectIdentityImpl(TARGET_CLASS, 101), 101,
this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));
MutableAcl childAcl = new AclImpl(new ObjectIdentityImpl(TARGET_CLASS, 102), 102,
this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));

childAcl.setParent(parentAcl);

assertThatIllegalArgumentException().isThrownBy(() -> parentAcl.setParent(childAcl));
}

@Test
public void setParentRejectsIndirectAncestor() {
MutableAcl grandParentAcl = new AclImpl(new ObjectIdentityImpl(TARGET_CLASS, 101), 101,
this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));
MutableAcl parentAcl = new AclImpl(new ObjectIdentityImpl(TARGET_CLASS, 102), 102,
this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));
MutableAcl childAcl = new AclImpl(new ObjectIdentityImpl(TARGET_CLASS, 103), 103,
this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));

parentAcl.setParent(grandParentAcl);
childAcl.setParent(parentAcl);

assertThatIllegalArgumentException().isThrownBy(() -> grandParentAcl.setParent(childAcl));
}

@Test
public void isSidLoadedBehavesAsExpected() {
List<Sid> loadedSids = Arrays.asList(new PrincipalSid("ben"), new GrantedAuthoritySid("ROLE_IGNORED"));
Expand Down