|
@@ -13,21 +13,41 @@
|
|
* See the License for the specific language governing permissions and
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* limitations under the License.
|
|
*/
|
|
*/
|
|
-package org.springframework.security.acls.domain;
|
|
|
|
|
|
|
|
-import static org.assertj.core.api.Assertions.*;
|
|
|
|
-import static org.mockito.Mockito.*;
|
|
|
|
|
|
+package org.springframework.security.acls.domain;
|
|
|
|
|
|
-import org.junit.*;
|
|
|
|
-import org.springframework.security.acls.model.*;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import org.junit.After;
|
|
|
|
+import org.junit.Before;
|
|
|
|
+import org.junit.Test;
|
|
|
|
+
|
|
|
|
+import org.springframework.security.acls.model.AccessControlEntry;
|
|
|
|
+import org.springframework.security.acls.model.Acl;
|
|
|
|
+import org.springframework.security.acls.model.AlreadyExistsException;
|
|
|
|
+import org.springframework.security.acls.model.AuditableAccessControlEntry;
|
|
|
|
+import org.springframework.security.acls.model.AuditableAcl;
|
|
|
|
+import org.springframework.security.acls.model.ChildrenExistException;
|
|
|
|
+import org.springframework.security.acls.model.MutableAcl;
|
|
|
|
+import org.springframework.security.acls.model.MutableAclService;
|
|
|
|
+import org.springframework.security.acls.model.NotFoundException;
|
|
|
|
+import org.springframework.security.acls.model.ObjectIdentity;
|
|
|
|
+import org.springframework.security.acls.model.Permission;
|
|
|
|
+import org.springframework.security.acls.model.PermissionGrantingStrategy;
|
|
|
|
+import org.springframework.security.acls.model.Sid;
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.util.FieldUtils;
|
|
import org.springframework.security.util.FieldUtils;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
+import static org.assertj.core.api.Assertions.fail;
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Tests for {@link AclImpl}.
|
|
* Tests for {@link AclImpl}.
|
|
@@ -35,33 +55,41 @@ import java.util.*;
|
|
* @author Andrei Stefan
|
|
* @author Andrei Stefan
|
|
*/
|
|
*/
|
|
public class AclImplTests {
|
|
public class AclImplTests {
|
|
|
|
+
|
|
private static final String TARGET_CLASS = "org.springframework.security.acls.TargetObject";
|
|
private static final String TARGET_CLASS = "org.springframework.security.acls.TargetObject";
|
|
|
|
+
|
|
private static final List<Permission> READ = Arrays.asList(BasePermission.READ);
|
|
private static final List<Permission> READ = Arrays.asList(BasePermission.READ);
|
|
|
|
+
|
|
private static final List<Permission> WRITE = Arrays.asList(BasePermission.WRITE);
|
|
private static final List<Permission> WRITE = Arrays.asList(BasePermission.WRITE);
|
|
|
|
+
|
|
private static final List<Permission> CREATE = Arrays.asList(BasePermission.CREATE);
|
|
private static final List<Permission> CREATE = Arrays.asList(BasePermission.CREATE);
|
|
|
|
+
|
|
private static final List<Permission> DELETE = Arrays.asList(BasePermission.DELETE);
|
|
private static final List<Permission> DELETE = Arrays.asList(BasePermission.DELETE);
|
|
|
|
+
|
|
private static final List<Sid> SCOTT = Arrays.asList((Sid) new PrincipalSid("scott"));
|
|
private static final List<Sid> SCOTT = Arrays.asList((Sid) new PrincipalSid("scott"));
|
|
|
|
+
|
|
private static final List<Sid> BEN = Arrays.asList((Sid) new PrincipalSid("ben"));
|
|
private static final List<Sid> BEN = Arrays.asList((Sid) new PrincipalSid("ben"));
|
|
|
|
|
|
- Authentication auth = new TestingAuthenticationToken("joe", "ignored",
|
|
|
|
- "ROLE_ADMINISTRATOR");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("joe", "ignored", "ROLE_ADMINISTRATOR");
|
|
|
|
+
|
|
AclAuthorizationStrategy authzStrategy;
|
|
AclAuthorizationStrategy authzStrategy;
|
|
|
|
+
|
|
PermissionGrantingStrategy pgs;
|
|
PermissionGrantingStrategy pgs;
|
|
|
|
+
|
|
AuditLogger mockAuditLogger;
|
|
AuditLogger mockAuditLogger;
|
|
|
|
+
|
|
ObjectIdentity objectIdentity = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
ObjectIdentity objectIdentity = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
- private DefaultPermissionFactory permissionFactory;
|
|
|
|
|
|
|
|
- // ~ Methods
|
|
|
|
- // ========================================================================================================
|
|
|
|
|
|
+ private DefaultPermissionFactory permissionFactory;
|
|
|
|
|
|
@Before
|
|
@Before
|
|
public void setUp() {
|
|
public void setUp() {
|
|
- SecurityContextHolder.getContext().setAuthentication(auth);
|
|
|
|
- authzStrategy = mock(AclAuthorizationStrategy.class);
|
|
|
|
- mockAuditLogger = mock(AuditLogger.class);
|
|
|
|
- pgs = new DefaultPermissionGrantingStrategy(mockAuditLogger);
|
|
|
|
- auth.setAuthenticated(true);
|
|
|
|
- permissionFactory = new DefaultPermissionFactory();
|
|
|
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(this.auth);
|
|
|
|
+ this.authzStrategy = mock(AclAuthorizationStrategy.class);
|
|
|
|
+ this.mockAuditLogger = mock(AuditLogger.class);
|
|
|
|
+ this.pgs = new DefaultPermissionGrantingStrategy(this.mockAuditLogger);
|
|
|
|
+ this.auth.setAuthenticated(true);
|
|
|
|
+ this.permissionFactory = new DefaultPermissionFactory();
|
|
}
|
|
}
|
|
|
|
|
|
@After
|
|
@After
|
|
@@ -72,44 +100,43 @@ public class AclImplTests {
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@Test(expected = IllegalArgumentException.class)
|
|
public void constructorsRejectNullObjectIdentity() {
|
|
public void constructorsRejectNullObjectIdentity() {
|
|
try {
|
|
try {
|
|
- new AclImpl(null, 1, authzStrategy, pgs, null, null, true, new PrincipalSid(
|
|
|
|
- "joe"));
|
|
|
|
|
|
+ new AclImpl(null, 1, this.authzStrategy, this.pgs, null, null, true, new PrincipalSid("joe"));
|
|
fail("Should have thrown IllegalArgumentException");
|
|
fail("Should have thrown IllegalArgumentException");
|
|
}
|
|
}
|
|
catch (IllegalArgumentException expected) {
|
|
catch (IllegalArgumentException expected) {
|
|
}
|
|
}
|
|
- new AclImpl(null, 1, authzStrategy, mockAuditLogger);
|
|
|
|
|
|
+ new AclImpl(null, 1, this.authzStrategy, this.mockAuditLogger);
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@Test(expected = IllegalArgumentException.class)
|
|
public void constructorsRejectNullId() {
|
|
public void constructorsRejectNullId() {
|
|
try {
|
|
try {
|
|
- new AclImpl(objectIdentity, null, authzStrategy, pgs, null, null, true,
|
|
|
|
|
|
+ new AclImpl(this.objectIdentity, null, this.authzStrategy, this.pgs, null, null, true,
|
|
new PrincipalSid("joe"));
|
|
new PrincipalSid("joe"));
|
|
fail("Should have thrown IllegalArgumentException");
|
|
fail("Should have thrown IllegalArgumentException");
|
|
}
|
|
}
|
|
catch (IllegalArgumentException expected) {
|
|
catch (IllegalArgumentException expected) {
|
|
}
|
|
}
|
|
- new AclImpl(objectIdentity, null, authzStrategy, mockAuditLogger);
|
|
|
|
|
|
+ new AclImpl(this.objectIdentity, null, this.authzStrategy, this.mockAuditLogger);
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@Test(expected = IllegalArgumentException.class)
|
|
public void constructorsRejectNullAclAuthzStrategy() {
|
|
public void constructorsRejectNullAclAuthzStrategy() {
|
|
try {
|
|
try {
|
|
- new AclImpl(objectIdentity, 1, null, new DefaultPermissionGrantingStrategy(
|
|
|
|
- mockAuditLogger), null, null, true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ new AclImpl(this.objectIdentity, 1, null, new DefaultPermissionGrantingStrategy(this.mockAuditLogger), null,
|
|
|
|
+ null, true, new PrincipalSid("joe"));
|
|
fail("It should have thrown IllegalArgumentException");
|
|
fail("It should have thrown IllegalArgumentException");
|
|
}
|
|
}
|
|
catch (IllegalArgumentException expected) {
|
|
catch (IllegalArgumentException expected) {
|
|
}
|
|
}
|
|
- new AclImpl(objectIdentity, 1, null, mockAuditLogger);
|
|
|
|
|
|
+ new AclImpl(this.objectIdentity, 1, null, this.mockAuditLogger);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void insertAceRejectsNullParameters() {
|
|
public void insertAceRejectsNullParameters() {
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
try {
|
|
try {
|
|
acl.insertAce(0, null, new GrantedAuthoritySid("ROLE_IGNORED"), true);
|
|
acl.insertAce(0, null, new GrantedAuthoritySid("ROLE_IGNORED"), true);
|
|
fail("It should have thrown IllegalArgumentException");
|
|
fail("It should have thrown IllegalArgumentException");
|
|
@@ -126,10 +153,9 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void insertAceAddsElementAtCorrectIndex() {
|
|
public void insertAceAddsElementAtCorrectIndex() {
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
-
|
|
|
|
// Insert one permission
|
|
// Insert one permission
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
@@ -137,9 +163,7 @@ public class AclImplTests {
|
|
assertThat(acl.getEntries()).hasSize(1);
|
|
assertThat(acl.getEntries()).hasSize(1);
|
|
assertThat(acl).isEqualTo(acl.getEntries().get(0).getAcl());
|
|
assertThat(acl).isEqualTo(acl.getEntries().get(0).getAcl());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
- assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST1"));
|
|
|
|
-
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST1"));
|
|
// Add a second permission
|
|
// Add a second permission
|
|
acl.insertAce(1, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"), true);
|
|
acl.insertAce(1, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
@@ -147,71 +171,54 @@ public class AclImplTests {
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
assertThat(acl).isEqualTo(acl.getEntries().get(1).getAcl());
|
|
assertThat(acl).isEqualTo(acl.getEntries().get(1).getAcl());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
- assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST2"));
|
|
|
|
-
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST2"));
|
|
// Add a third permission, after the first one
|
|
// Add a third permission, after the first one
|
|
- acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_TEST3"),
|
|
|
|
- false);
|
|
|
|
|
|
+ acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_TEST3"), false);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
assertThat(acl.getEntries()).hasSize(3);
|
|
assertThat(acl.getEntries()).hasSize(3);
|
|
// Check the third entry was added between the two existent ones
|
|
// Check the third entry was added between the two existent ones
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
- assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST1"));
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST1"));
|
|
assertThat(BasePermission.WRITE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
assertThat(BasePermission.WRITE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
- assertThat(acl.getEntries().get(1).getSid()).isEqualTo( new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST3"));
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST3"));
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(2).getPermission());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(2).getPermission());
|
|
- assertThat(acl.getEntries().get(2).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST2"));
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(2).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST2"));
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = NotFoundException.class)
|
|
@Test(expected = NotFoundException.class)
|
|
public void insertAceFailsForNonExistentElement() {
|
|
public void insertAceFailsForNonExistentElement() {
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
-
|
|
|
|
// Insert one permission
|
|
// Insert one permission
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
-
|
|
|
|
- acl.insertAce(55, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"),
|
|
|
|
- true);
|
|
|
|
|
|
+ acl.insertAce(55, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"), true);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void deleteAceKeepsInitialOrdering() {
|
|
public void deleteAceKeepsInitialOrdering() {
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
-
|
|
|
|
// Add several permissions
|
|
// Add several permissions
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST1"), true);
|
|
acl.insertAce(1, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"), true);
|
|
acl.insertAce(1, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST2"), true);
|
|
acl.insertAce(2, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST3"), true);
|
|
acl.insertAce(2, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST3"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
-
|
|
|
|
// Delete first permission and check the order of the remaining permissions is
|
|
// Delete first permission and check the order of the remaining permissions is
|
|
// kept
|
|
// kept
|
|
acl.deleteAce(0);
|
|
acl.deleteAce(0);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
- assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST2"));
|
|
|
|
- assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST3"));
|
|
|
|
-
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST2"));
|
|
|
|
+ assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST3"));
|
|
// Add one more permission and remove the permission in the middle
|
|
// Add one more permission and remove the permission in the middle
|
|
acl.insertAce(2, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST4"), true);
|
|
acl.insertAce(2, BasePermission.READ, new GrantedAuthoritySid("ROLE_TEST4"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
acl.deleteAce(1);
|
|
acl.deleteAce(1);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
- assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST2"));
|
|
|
|
- assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_TEST4"));
|
|
|
|
-
|
|
|
|
|
|
+ assertThat(acl.getEntries().get(0).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST2"));
|
|
|
|
+ assertThat(acl.getEntries().get(1).getSid()).isEqualTo(new GrantedAuthoritySid("ROLE_TEST4"));
|
|
// Remove remaining permissions
|
|
// Remove remaining permissions
|
|
acl.deleteAce(1);
|
|
acl.deleteAce(1);
|
|
acl.deleteAce(0);
|
|
acl.deleteAce(0);
|
|
@@ -221,10 +228,10 @@ public class AclImplTests {
|
|
@Test
|
|
@Test
|
|
public void deleteAceFailsForNonExistentElement() {
|
|
public void deleteAceFailsForNonExistentElement() {
|
|
AclAuthorizationStrategyImpl strategy = new AclAuthorizationStrategyImpl(
|
|
AclAuthorizationStrategyImpl strategy = new AclAuthorizationStrategyImpl(
|
|
- new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority(
|
|
|
|
- "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL"));
|
|
|
|
- MutableAcl acl = new AclImpl(objectIdentity, (1), strategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority("ROLE_AUDITING"),
|
|
|
|
+ new SimpleGrantedAuthority("ROLE_GENERAL"));
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, (1), strategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
try {
|
|
try {
|
|
acl.deleteAce(99);
|
|
acl.deleteAce(99);
|
|
fail("It should have thrown NotFoundException");
|
|
fail("It should have thrown NotFoundException");
|
|
@@ -235,8 +242,8 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void isGrantingRejectsEmptyParameters() {
|
|
public void isGrantingRejectsEmptyParameters() {
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
Sid ben = new PrincipalSid("ben");
|
|
Sid ben = new PrincipalSid("ben");
|
|
try {
|
|
try {
|
|
acl.isGranted(new ArrayList<>(0), Arrays.asList(ben), false);
|
|
acl.isGranted(new ArrayList<>(0), Arrays.asList(ben), false);
|
|
@@ -254,28 +261,21 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void isGrantingGrantsAccessForAclWithNoParent() {
|
|
public void isGrantingGrantsAccessForAclWithNoParent() {
|
|
- Authentication auth = new TestingAuthenticationToken("ben", "ignored",
|
|
|
|
- "ROLE_GENERAL", "ROLE_GUEST");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_GENERAL", "ROLE_GUEST");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
ObjectIdentity rootOid = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
ObjectIdentity rootOid = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
-
|
|
|
|
// Create an ACL which owner is not the authenticated principal
|
|
// Create an ACL which owner is not the authenticated principal
|
|
- MutableAcl rootAcl = new AclImpl(rootOid, 1, authzStrategy, pgs, null, null,
|
|
|
|
- false, new PrincipalSid("joe"));
|
|
|
|
-
|
|
|
|
|
|
+ MutableAcl rootAcl = new AclImpl(rootOid, 1, this.authzStrategy, this.pgs, null, null, false,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
// Grant some permissions
|
|
// Grant some permissions
|
|
rootAcl.insertAce(0, BasePermission.READ, new PrincipalSid("ben"), false);
|
|
rootAcl.insertAce(0, BasePermission.READ, new PrincipalSid("ben"), false);
|
|
rootAcl.insertAce(1, BasePermission.WRITE, new PrincipalSid("scott"), true);
|
|
rootAcl.insertAce(1, BasePermission.WRITE, new PrincipalSid("scott"), true);
|
|
rootAcl.insertAce(2, BasePermission.WRITE, new PrincipalSid("rod"), false);
|
|
rootAcl.insertAce(2, BasePermission.WRITE, new PrincipalSid("rod"), false);
|
|
- rootAcl.insertAce(3, BasePermission.WRITE, new GrantedAuthoritySid(
|
|
|
|
- "WRITE_ACCESS_ROLE"), true);
|
|
|
|
-
|
|
|
|
|
|
+ rootAcl.insertAce(3, BasePermission.WRITE, new GrantedAuthoritySid("WRITE_ACCESS_ROLE"), true);
|
|
// Check permissions granting
|
|
// Check permissions granting
|
|
- List<Permission> permissions = Arrays.asList(BasePermission.READ,
|
|
|
|
- BasePermission.CREATE);
|
|
|
|
- List<Sid> sids = Arrays.asList(new PrincipalSid("ben"), new GrantedAuthoritySid(
|
|
|
|
- "ROLE_GUEST"));
|
|
|
|
|
|
+ List<Permission> permissions = Arrays.asList(BasePermission.READ, BasePermission.CREATE);
|
|
|
|
+ List<Sid> sids = Arrays.asList(new PrincipalSid("ben"), new GrantedAuthoritySid("ROLE_GUEST"));
|
|
assertThat(rootAcl.isGranted(permissions, sids, false)).isFalse();
|
|
assertThat(rootAcl.isGranted(permissions, sids, false)).isFalse();
|
|
try {
|
|
try {
|
|
rootAcl.isGranted(permissions, SCOTT, false);
|
|
rootAcl.isGranted(permissions, SCOTT, false);
|
|
@@ -284,14 +284,14 @@ public class AclImplTests {
|
|
catch (NotFoundException expected) {
|
|
catch (NotFoundException expected) {
|
|
}
|
|
}
|
|
assertThat(rootAcl.isGranted(WRITE, SCOTT, false)).isTrue();
|
|
assertThat(rootAcl.isGranted(WRITE, SCOTT, false)).isTrue();
|
|
- assertThat(rootAcl.isGranted(WRITE, Arrays.asList(new PrincipalSid("rod"),
|
|
|
|
- new GrantedAuthoritySid("WRITE_ACCESS_ROLE")), false)).isFalse();
|
|
|
|
- assertThat(rootAcl.isGranted(WRITE, Arrays.asList(new GrantedAuthoritySid(
|
|
|
|
- "WRITE_ACCESS_ROLE"), new PrincipalSid("rod")), false)).isTrue();
|
|
|
|
|
|
+ assertThat(rootAcl.isGranted(WRITE,
|
|
|
|
+ Arrays.asList(new PrincipalSid("rod"), new GrantedAuthoritySid("WRITE_ACCESS_ROLE")), false)).isFalse();
|
|
|
|
+ assertThat(rootAcl.isGranted(WRITE,
|
|
|
|
+ Arrays.asList(new GrantedAuthoritySid("WRITE_ACCESS_ROLE"), new PrincipalSid("rod")), false)).isTrue();
|
|
try {
|
|
try {
|
|
// Change the type of the Sid and check the granting process
|
|
// Change the type of the Sid and check the granting process
|
|
- rootAcl.isGranted(WRITE, Arrays.asList(new GrantedAuthoritySid("rod"),
|
|
|
|
- new PrincipalSid("WRITE_ACCESS_ROLE")), false);
|
|
|
|
|
|
+ rootAcl.isGranted(WRITE,
|
|
|
|
+ Arrays.asList(new GrantedAuthoritySid("rod"), new PrincipalSid("WRITE_ACCESS_ROLE")), false);
|
|
fail("It should have thrown NotFoundException");
|
|
fail("It should have thrown NotFoundException");
|
|
}
|
|
}
|
|
catch (NotFoundException expected) {
|
|
catch (NotFoundException expected) {
|
|
@@ -300,8 +300,7 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void isGrantingGrantsAccessForInheritableAcls() {
|
|
public void isGrantingGrantsAccessForInheritableAcls() {
|
|
- Authentication auth = new TestingAuthenticationToken("ben", "ignored",
|
|
|
|
- "ROLE_GENERAL");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_GENERAL");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
ObjectIdentity grandParentOid = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
ObjectIdentity grandParentOid = new ObjectIdentityImpl(TARGET_CLASS, 100);
|
|
@@ -309,60 +308,44 @@ public class AclImplTests {
|
|
ObjectIdentity parentOid2 = new ObjectIdentityImpl(TARGET_CLASS, 102);
|
|
ObjectIdentity parentOid2 = new ObjectIdentityImpl(TARGET_CLASS, 102);
|
|
ObjectIdentity childOid1 = new ObjectIdentityImpl(TARGET_CLASS, 103);
|
|
ObjectIdentity childOid1 = new ObjectIdentityImpl(TARGET_CLASS, 103);
|
|
ObjectIdentity childOid2 = new ObjectIdentityImpl(TARGET_CLASS, 104);
|
|
ObjectIdentity childOid2 = new ObjectIdentityImpl(TARGET_CLASS, 104);
|
|
-
|
|
|
|
// Create ACLs
|
|
// Create ACLs
|
|
PrincipalSid joe = new PrincipalSid("joe");
|
|
PrincipalSid joe = new PrincipalSid("joe");
|
|
- MutableAcl grandParentAcl = new AclImpl(grandParentOid, 1, authzStrategy, pgs,
|
|
|
|
- null, null, false, joe);
|
|
|
|
- MutableAcl parentAcl1 = new AclImpl(parentOid1, 2, authzStrategy, pgs, null,
|
|
|
|
- null, true, joe);
|
|
|
|
- MutableAcl parentAcl2 = new AclImpl(parentOid2, 3, authzStrategy, pgs, null,
|
|
|
|
- null, true, joe);
|
|
|
|
- MutableAcl childAcl1 = new AclImpl(childOid1, 4, authzStrategy, pgs, null, null,
|
|
|
|
- true, joe);
|
|
|
|
- MutableAcl childAcl2 = new AclImpl(childOid2, 4, authzStrategy, pgs, null, null,
|
|
|
|
- false, joe);
|
|
|
|
-
|
|
|
|
|
|
+ MutableAcl grandParentAcl = new AclImpl(grandParentOid, 1, this.authzStrategy, this.pgs, null, null, false,
|
|
|
|
+ joe);
|
|
|
|
+ MutableAcl parentAcl1 = new AclImpl(parentOid1, 2, this.authzStrategy, this.pgs, null, null, true, joe);
|
|
|
|
+ MutableAcl parentAcl2 = new AclImpl(parentOid2, 3, this.authzStrategy, this.pgs, null, null, true, joe);
|
|
|
|
+ MutableAcl childAcl1 = new AclImpl(childOid1, 4, this.authzStrategy, this.pgs, null, null, true, joe);
|
|
|
|
+ MutableAcl childAcl2 = new AclImpl(childOid2, 4, this.authzStrategy, this.pgs, null, null, false, joe);
|
|
// Create hierarchies
|
|
// Create hierarchies
|
|
childAcl2.setParent(childAcl1);
|
|
childAcl2.setParent(childAcl1);
|
|
childAcl1.setParent(parentAcl1);
|
|
childAcl1.setParent(parentAcl1);
|
|
parentAcl2.setParent(grandParentAcl);
|
|
parentAcl2.setParent(grandParentAcl);
|
|
parentAcl1.setParent(grandParentAcl);
|
|
parentAcl1.setParent(grandParentAcl);
|
|
-
|
|
|
|
// Add some permissions
|
|
// Add some permissions
|
|
- grandParentAcl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid(
|
|
|
|
- "ROLE_USER_READ"), true);
|
|
|
|
|
|
+ grandParentAcl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
grandParentAcl.insertAce(1, BasePermission.WRITE, new PrincipalSid("ben"), true);
|
|
grandParentAcl.insertAce(1, BasePermission.WRITE, new PrincipalSid("ben"), true);
|
|
- grandParentAcl
|
|
|
|
- .insertAce(2, BasePermission.DELETE, new PrincipalSid("ben"), false);
|
|
|
|
- grandParentAcl.insertAce(3, BasePermission.DELETE, new PrincipalSid("scott"),
|
|
|
|
- true);
|
|
|
|
|
|
+ grandParentAcl.insertAce(2, BasePermission.DELETE, new PrincipalSid("ben"), false);
|
|
|
|
+ grandParentAcl.insertAce(3, BasePermission.DELETE, new PrincipalSid("scott"), true);
|
|
parentAcl1.insertAce(0, BasePermission.READ, new PrincipalSid("scott"), true);
|
|
parentAcl1.insertAce(0, BasePermission.READ, new PrincipalSid("scott"), true);
|
|
parentAcl1.insertAce(1, BasePermission.DELETE, new PrincipalSid("scott"), false);
|
|
parentAcl1.insertAce(1, BasePermission.DELETE, new PrincipalSid("scott"), false);
|
|
parentAcl2.insertAce(0, BasePermission.CREATE, new PrincipalSid("ben"), true);
|
|
parentAcl2.insertAce(0, BasePermission.CREATE, new PrincipalSid("ben"), true);
|
|
childAcl1.insertAce(0, BasePermission.CREATE, new PrincipalSid("scott"), true);
|
|
childAcl1.insertAce(0, BasePermission.CREATE, new PrincipalSid("scott"), true);
|
|
-
|
|
|
|
// Check granting process for parent1
|
|
// Check granting process for parent1
|
|
assertThat(parentAcl1.isGranted(READ, SCOTT, false)).isTrue();
|
|
assertThat(parentAcl1.isGranted(READ, SCOTT, false)).isTrue();
|
|
- assertThat(parentAcl1.isGranted(READ,
|
|
|
|
- Arrays.asList((Sid) new GrantedAuthoritySid("ROLE_USER_READ")), false))
|
|
|
|
|
|
+ assertThat(parentAcl1.isGranted(READ, Arrays.asList((Sid) new GrantedAuthoritySid("ROLE_USER_READ")), false))
|
|
.isTrue();
|
|
.isTrue();
|
|
assertThat(parentAcl1.isGranted(WRITE, BEN, false)).isTrue();
|
|
assertThat(parentAcl1.isGranted(WRITE, BEN, false)).isTrue();
|
|
assertThat(parentAcl1.isGranted(DELETE, BEN, false)).isFalse();
|
|
assertThat(parentAcl1.isGranted(DELETE, BEN, false)).isFalse();
|
|
assertThat(parentAcl1.isGranted(DELETE, SCOTT, false)).isFalse();
|
|
assertThat(parentAcl1.isGranted(DELETE, SCOTT, false)).isFalse();
|
|
-
|
|
|
|
// Check granting process for parent2
|
|
// Check granting process for parent2
|
|
assertThat(parentAcl2.isGranted(CREATE, BEN, false)).isTrue();
|
|
assertThat(parentAcl2.isGranted(CREATE, BEN, false)).isTrue();
|
|
assertThat(parentAcl2.isGranted(WRITE, BEN, false)).isTrue();
|
|
assertThat(parentAcl2.isGranted(WRITE, BEN, false)).isTrue();
|
|
assertThat(parentAcl2.isGranted(DELETE, BEN, false)).isFalse();
|
|
assertThat(parentAcl2.isGranted(DELETE, BEN, false)).isFalse();
|
|
-
|
|
|
|
// Check granting process for child1
|
|
// Check granting process for child1
|
|
assertThat(childAcl1.isGranted(CREATE, SCOTT, false)).isTrue();
|
|
assertThat(childAcl1.isGranted(CREATE, SCOTT, false)).isTrue();
|
|
- assertThat(childAcl1.isGranted(READ,
|
|
|
|
- Arrays.asList((Sid) new GrantedAuthoritySid("ROLE_USER_READ")), false))
|
|
|
|
|
|
+ assertThat(childAcl1.isGranted(READ, Arrays.asList((Sid) new GrantedAuthoritySid("ROLE_USER_READ")), false))
|
|
.isTrue();
|
|
.isTrue();
|
|
assertThat(childAcl1.isGranted(DELETE, BEN, false)).isFalse();
|
|
assertThat(childAcl1.isGranted(DELETE, BEN, false)).isFalse();
|
|
-
|
|
|
|
// Check granting process for child2 (doesn't inherit the permissions from its
|
|
// Check granting process for child2 (doesn't inherit the permissions from its
|
|
// parent)
|
|
// parent)
|
|
try {
|
|
try {
|
|
@@ -372,8 +355,7 @@ public class AclImplTests {
|
|
catch (NotFoundException expected) {
|
|
catch (NotFoundException expected) {
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- childAcl2.isGranted(CREATE,
|
|
|
|
- Arrays.asList((Sid) new PrincipalSid("joe")), false);
|
|
|
|
|
|
+ childAcl2.isGranted(CREATE, Arrays.asList((Sid) new PrincipalSid("joe")), false);
|
|
fail("It should have thrown NotFoundException");
|
|
fail("It should have thrown NotFoundException");
|
|
}
|
|
}
|
|
catch (NotFoundException expected) {
|
|
catch (NotFoundException expected) {
|
|
@@ -382,30 +364,23 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void updatedAceValuesAreCorrectlyReflectedInAcl() {
|
|
public void updatedAceValuesAreCorrectlyReflectedInAcl() {
|
|
- Authentication auth = new TestingAuthenticationToken("ben", "ignored",
|
|
|
|
- "ROLE_GENERAL");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_GENERAL");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- false, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, false,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
-
|
|
|
|
- acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
- acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
|
|
+ acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
|
|
+ acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
acl.insertAce(2, BasePermission.CREATE, new PrincipalSid("ben"), true);
|
|
acl.insertAce(2, BasePermission.CREATE, new PrincipalSid("ben"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
-
|
|
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.READ).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.WRITE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
assertThat(BasePermission.WRITE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
assertThat(BasePermission.CREATE).isEqualTo(acl.getEntries().get(2).getPermission());
|
|
assertThat(BasePermission.CREATE).isEqualTo(acl.getEntries().get(2).getPermission());
|
|
-
|
|
|
|
// Change each permission
|
|
// Change each permission
|
|
acl.updateAce(0, BasePermission.CREATE);
|
|
acl.updateAce(0, BasePermission.CREATE);
|
|
acl.updateAce(1, BasePermission.DELETE);
|
|
acl.updateAce(1, BasePermission.DELETE);
|
|
acl.updateAce(2, BasePermission.READ);
|
|
acl.updateAce(2, BasePermission.READ);
|
|
-
|
|
|
|
// Check the change was successfully made
|
|
// Check the change was successfully made
|
|
assertThat(BasePermission.CREATE).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.CREATE).isEqualTo(acl.getEntries().get(0).getPermission());
|
|
assertThat(BasePermission.DELETE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
assertThat(BasePermission.DELETE).isEqualTo(acl.getEntries().get(1).getPermission());
|
|
@@ -414,37 +389,22 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void auditableEntryFlagsAreUpdatedCorrectly() {
|
|
public void auditableEntryFlagsAreUpdatedCorrectly() {
|
|
- Authentication auth = new TestingAuthenticationToken("ben", "ignored",
|
|
|
|
- "ROLE_AUDITING", "ROLE_GENERAL");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_AUDITING", "ROLE_GENERAL");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- false, new PrincipalSid("joe"));
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, false,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
-
|
|
|
|
- acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
- acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
|
|
+ acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
|
|
+ acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
-
|
|
|
|
- assertThat(((AuditableAccessControlEntry) acl.getEntries().get(0))
|
|
|
|
- .isAuditFailure())
|
|
|
|
- .isFalse();
|
|
|
|
- assertThat(((AuditableAccessControlEntry) acl.getEntries().get(1))
|
|
|
|
- .isAuditFailure())
|
|
|
|
- .isFalse();
|
|
|
|
- assertThat(((AuditableAccessControlEntry) acl.getEntries().get(0))
|
|
|
|
- .isAuditSuccess())
|
|
|
|
- .isFalse();
|
|
|
|
- assertThat(((AuditableAccessControlEntry) acl.getEntries().get(1))
|
|
|
|
- .isAuditSuccess())
|
|
|
|
- .isFalse();
|
|
|
|
-
|
|
|
|
|
|
+ assertThat(((AuditableAccessControlEntry) acl.getEntries().get(0)).isAuditFailure()).isFalse();
|
|
|
|
+ assertThat(((AuditableAccessControlEntry) acl.getEntries().get(1)).isAuditFailure()).isFalse();
|
|
|
|
+ assertThat(((AuditableAccessControlEntry) acl.getEntries().get(0)).isAuditSuccess()).isFalse();
|
|
|
|
+ assertThat(((AuditableAccessControlEntry) acl.getEntries().get(1)).isAuditSuccess()).isFalse();
|
|
// Change each permission
|
|
// Change each permission
|
|
((AuditableAcl) acl).updateAuditing(0, true, true);
|
|
((AuditableAcl) acl).updateAuditing(0, true, true);
|
|
((AuditableAcl) acl).updateAuditing(1, true, true);
|
|
((AuditableAcl) acl).updateAuditing(1, true, true);
|
|
-
|
|
|
|
// Check the change was successfuly made
|
|
// Check the change was successfuly made
|
|
assertThat(acl.getEntries()).extracting("auditSuccess").containsOnly(true, true);
|
|
assertThat(acl.getEntries()).extracting("auditSuccess").containsOnly(true, true);
|
|
assertThat(acl.getEntries()).extracting("auditFailure").containsOnly(true, true);
|
|
assertThat(acl.getEntries()).extracting("auditFailure").containsOnly(true, true);
|
|
@@ -452,86 +412,74 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void gettersAndSettersAreConsistent() {
|
|
public void gettersAndSettersAreConsistent() {
|
|
- Authentication auth = new TestingAuthenticationToken("ben", "ignored",
|
|
|
|
- "ROLE_GENERAL");
|
|
|
|
|
|
+ Authentication auth = new TestingAuthenticationToken("ben", "ignored", "ROLE_GENERAL");
|
|
auth.setAuthenticated(true);
|
|
auth.setAuthenticated(true);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
|
ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, (100));
|
|
ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, (100));
|
|
ObjectIdentity identity2 = new ObjectIdentityImpl(TARGET_CLASS, (101));
|
|
ObjectIdentity identity2 = new ObjectIdentityImpl(TARGET_CLASS, (101));
|
|
- MutableAcl acl = new AclImpl(identity, 1, authzStrategy, pgs, null, null, true,
|
|
|
|
|
|
+ MutableAcl acl = new AclImpl(identity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
|
|
+ MutableAcl parentAcl = new AclImpl(identity2, 2, this.authzStrategy, this.pgs, null, null, true,
|
|
new PrincipalSid("joe"));
|
|
new PrincipalSid("joe"));
|
|
- MutableAcl parentAcl = new AclImpl(identity2, 2, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
- acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
- acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"),
|
|
|
|
- true);
|
|
|
|
|
|
+ acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
|
|
+ acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER_READ"), true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
-
|
|
|
|
assertThat(1).isEqualTo(acl.getId());
|
|
assertThat(1).isEqualTo(acl.getId());
|
|
assertThat(identity).isEqualTo(acl.getObjectIdentity());
|
|
assertThat(identity).isEqualTo(acl.getObjectIdentity());
|
|
assertThat(new PrincipalSid("joe")).isEqualTo(acl.getOwner());
|
|
assertThat(new PrincipalSid("joe")).isEqualTo(acl.getOwner());
|
|
assertThat(acl.getParentAcl()).isNull();
|
|
assertThat(acl.getParentAcl()).isNull();
|
|
assertThat(acl.isEntriesInheriting()).isTrue();
|
|
assertThat(acl.isEntriesInheriting()).isTrue();
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
assertThat(acl.getEntries()).hasSize(2);
|
|
-
|
|
|
|
acl.setParent(parentAcl);
|
|
acl.setParent(parentAcl);
|
|
assertThat(parentAcl).isEqualTo(acl.getParentAcl());
|
|
assertThat(parentAcl).isEqualTo(acl.getParentAcl());
|
|
-
|
|
|
|
acl.setEntriesInheriting(false);
|
|
acl.setEntriesInheriting(false);
|
|
assertThat(acl.isEntriesInheriting()).isFalse();
|
|
assertThat(acl.isEntriesInheriting()).isFalse();
|
|
-
|
|
|
|
acl.setOwner(new PrincipalSid("ben"));
|
|
acl.setOwner(new PrincipalSid("ben"));
|
|
assertThat(new PrincipalSid("ben")).isEqualTo(acl.getOwner());
|
|
assertThat(new PrincipalSid("ben")).isEqualTo(acl.getOwner());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void isSidLoadedBehavesAsExpected() {
|
|
public void isSidLoadedBehavesAsExpected() {
|
|
- List<Sid> loadedSids = Arrays.asList(new PrincipalSid("ben"),
|
|
|
|
- new GrantedAuthoritySid("ROLE_IGNORED"));
|
|
|
|
- MutableAcl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null,
|
|
|
|
- loadedSids, true, new PrincipalSid("joe"));
|
|
|
|
-
|
|
|
|
|
|
+ List<Sid> loadedSids = Arrays.asList(new PrincipalSid("ben"), new GrantedAuthoritySid("ROLE_IGNORED"));
|
|
|
|
+ MutableAcl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, loadedSids, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
assertThat(acl.isSidLoaded(loadedSids)).isTrue();
|
|
assertThat(acl.isSidLoaded(loadedSids)).isTrue();
|
|
- assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid("ROLE_IGNORED"),
|
|
|
|
- new PrincipalSid("ben"))))
|
|
|
|
- .isTrue();
|
|
|
|
- assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
|
|
|
|
- "ROLE_IGNORED"))))
|
|
|
|
- .isTrue();
|
|
|
|
|
|
+ assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid("ROLE_IGNORED"), new PrincipalSid("ben"))))
|
|
|
|
+ .isTrue();
|
|
|
|
+ assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid("ROLE_IGNORED")))).isTrue();
|
|
assertThat(acl.isSidLoaded(BEN)).isTrue();
|
|
assertThat(acl.isSidLoaded(BEN)).isTrue();
|
|
assertThat(acl.isSidLoaded(null)).isTrue();
|
|
assertThat(acl.isSidLoaded(null)).isTrue();
|
|
assertThat(acl.isSidLoaded(new ArrayList<>(0))).isTrue();
|
|
assertThat(acl.isSidLoaded(new ArrayList<>(0))).isTrue();
|
|
- assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_IGNORED"))))
|
|
|
|
- .isTrue();
|
|
|
|
- assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_GENERAL"), new GrantedAuthoritySid("ROLE_IGNORED"))))
|
|
|
|
- .isFalse();
|
|
|
|
- assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
|
|
|
|
- "ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_GENERAL"))))
|
|
|
|
- .isFalse();
|
|
|
|
|
|
+ assertThat(acl.isSidLoaded(
|
|
|
|
+ Arrays.asList(new GrantedAuthoritySid("ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_IGNORED"))))
|
|
|
|
+ .isTrue();
|
|
|
|
+ assertThat(acl.isSidLoaded(
|
|
|
|
+ Arrays.asList(new GrantedAuthoritySid("ROLE_GENERAL"), new GrantedAuthoritySid("ROLE_IGNORED"))))
|
|
|
|
+ .isFalse();
|
|
|
|
+ assertThat(acl.isSidLoaded(
|
|
|
|
+ Arrays.asList(new GrantedAuthoritySid("ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_GENERAL"))))
|
|
|
|
+ .isFalse();
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = NotFoundException.class)
|
|
@Test(expected = NotFoundException.class)
|
|
public void insertAceRaisesNotFoundExceptionForIndexLessThanZero() {
|
|
public void insertAceRaisesNotFoundExceptionForIndexLessThanZero() {
|
|
- AclImpl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
acl.insertAce(-1, mock(Permission.class), mock(Sid.class), true);
|
|
acl.insertAce(-1, mock(Permission.class), mock(Sid.class), true);
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = NotFoundException.class)
|
|
@Test(expected = NotFoundException.class)
|
|
public void deleteAceRaisesNotFoundExceptionForIndexLessThanZero() {
|
|
public void deleteAceRaisesNotFoundExceptionForIndexLessThanZero() {
|
|
- AclImpl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
acl.deleteAce(-1);
|
|
acl.deleteAce(-1);
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = NotFoundException.class)
|
|
@Test(expected = NotFoundException.class)
|
|
public void insertAceRaisesNotFoundExceptionForIndexGreaterThanSize() {
|
|
public void insertAceRaisesNotFoundExceptionForIndexGreaterThanSize() {
|
|
- AclImpl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
// Insert at zero, OK.
|
|
// Insert at zero, OK.
|
|
acl.insertAce(0, mock(Permission.class), mock(Sid.class), true);
|
|
acl.insertAce(0, mock(Permission.class), mock(Sid.class), true);
|
|
// Size is now 1
|
|
// Size is now 1
|
|
@@ -541,8 +489,8 @@ public class AclImplTests {
|
|
// SEC-1151
|
|
// SEC-1151
|
|
@Test(expected = NotFoundException.class)
|
|
@Test(expected = NotFoundException.class)
|
|
public void deleteAceRaisesNotFoundExceptionForIndexEqualToSize() {
|
|
public void deleteAceRaisesNotFoundExceptionForIndexEqualToSize() {
|
|
- AclImpl acl = new AclImpl(objectIdentity, 1, authzStrategy, pgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, this.pgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
acl.insertAce(0, mock(Permission.class), mock(Sid.class), true);
|
|
acl.insertAce(0, mock(Permission.class), mock(Sid.class), true);
|
|
// Size is now 1
|
|
// Size is now 1
|
|
acl.deleteAce(1);
|
|
acl.deleteAce(1);
|
|
@@ -551,12 +499,9 @@ public class AclImplTests {
|
|
// SEC-1795
|
|
// SEC-1795
|
|
@Test
|
|
@Test
|
|
public void changingParentIsSuccessful() {
|
|
public void changingParentIsSuccessful() {
|
|
- AclImpl parentAcl = new AclImpl(objectIdentity, 1L, authzStrategy,
|
|
|
|
- mockAuditLogger);
|
|
|
|
- AclImpl childAcl = new AclImpl(objectIdentity, 2L, authzStrategy, mockAuditLogger);
|
|
|
|
- AclImpl changeParentAcl = new AclImpl(objectIdentity, 3L, authzStrategy,
|
|
|
|
- mockAuditLogger);
|
|
|
|
-
|
|
|
|
|
|
+ AclImpl parentAcl = new AclImpl(this.objectIdentity, 1L, this.authzStrategy, this.mockAuditLogger);
|
|
|
|
+ AclImpl childAcl = new AclImpl(this.objectIdentity, 2L, this.authzStrategy, this.mockAuditLogger);
|
|
|
|
+ AclImpl changeParentAcl = new AclImpl(this.objectIdentity, 3L, this.authzStrategy, this.mockAuditLogger);
|
|
childAcl.setParent(parentAcl);
|
|
childAcl.setParent(parentAcl);
|
|
childAcl.setParent(changeParentAcl);
|
|
childAcl.setParent(changeParentAcl);
|
|
}
|
|
}
|
|
@@ -564,11 +509,12 @@ public class AclImplTests {
|
|
// SEC-2342
|
|
// SEC-2342
|
|
@Test
|
|
@Test
|
|
public void maskPermissionGrantingStrategy() {
|
|
public void maskPermissionGrantingStrategy() {
|
|
- DefaultPermissionGrantingStrategy maskPgs = new MaskPermissionGrantingStrategy(mockAuditLogger);
|
|
|
|
|
|
+ DefaultPermissionGrantingStrategy maskPgs = new MaskPermissionGrantingStrategy(this.mockAuditLogger);
|
|
MockAclService service = new MockAclService();
|
|
MockAclService service = new MockAclService();
|
|
- AclImpl acl = new AclImpl(objectIdentity, 1, authzStrategy, maskPgs, null, null,
|
|
|
|
- true, new PrincipalSid("joe"));
|
|
|
|
- Permission permission = permissionFactory.buildFromMask(BasePermission.READ.getMask() | BasePermission.WRITE.getMask());
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(this.objectIdentity, 1, this.authzStrategy, maskPgs, null, null, true,
|
|
|
|
+ new PrincipalSid("joe"));
|
|
|
|
+ Permission permission = this.permissionFactory
|
|
|
|
+ .buildFromMask(BasePermission.READ.getMask() | BasePermission.WRITE.getMask());
|
|
Sid sid = new PrincipalSid("ben");
|
|
Sid sid = new PrincipalSid("ben");
|
|
acl.insertAce(0, permission, sid, true);
|
|
acl.insertAce(0, permission, sid, true);
|
|
service.updateAcl(acl);
|
|
service.updateAcl(acl);
|
|
@@ -579,27 +525,21 @@ public class AclImplTests {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void hashCodeWithoutStackOverFlow() throws Exception {
|
|
public void hashCodeWithoutStackOverFlow() throws Exception {
|
|
- //given
|
|
|
|
Sid sid = new PrincipalSid("pSid");
|
|
Sid sid = new PrincipalSid("pSid");
|
|
ObjectIdentity oid = new ObjectIdentityImpl("type", 1);
|
|
ObjectIdentity oid = new ObjectIdentityImpl("type", 1);
|
|
AclAuthorizationStrategy authStrategy = new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("role"));
|
|
AclAuthorizationStrategy authStrategy = new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("role"));
|
|
PermissionGrantingStrategy grantingStrategy = new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger());
|
|
PermissionGrantingStrategy grantingStrategy = new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger());
|
|
-
|
|
|
|
- AclImpl acl = new AclImpl(oid, 1L, authStrategy, grantingStrategy, null, null, false, sid);
|
|
|
|
|
|
+ AclImpl acl = new AclImpl(oid, 1L, authStrategy, grantingStrategy, null, null, false, sid);
|
|
AccessControlEntryImpl ace = new AccessControlEntryImpl(1L, acl, sid, BasePermission.READ, true, true, true);
|
|
AccessControlEntryImpl ace = new AccessControlEntryImpl(1L, acl, sid, BasePermission.READ, true, true, true);
|
|
-
|
|
|
|
- Field fieldAces = FieldUtils.getField(AclImpl.class, "aces");
|
|
|
|
|
|
+ Field fieldAces = FieldUtils.getField(AclImpl.class, "aces");
|
|
fieldAces.setAccessible(true);
|
|
fieldAces.setAccessible(true);
|
|
List<AccessControlEntryImpl> aces = (List<AccessControlEntryImpl>) fieldAces.get(acl);
|
|
List<AccessControlEntryImpl> aces = (List<AccessControlEntryImpl>) fieldAces.get(acl);
|
|
aces.add(ace);
|
|
aces.add(ace);
|
|
- //when - then none StackOverFlowError been raised
|
|
|
|
ace.hashCode();
|
|
ace.hashCode();
|
|
}
|
|
}
|
|
|
|
|
|
- // ~ Inner Classes
|
|
|
|
- // ==================================================================================================
|
|
|
|
-
|
|
|
|
private static class MaskPermissionGrantingStrategy extends DefaultPermissionGrantingStrategy {
|
|
private static class MaskPermissionGrantingStrategy extends DefaultPermissionGrantingStrategy {
|
|
|
|
+
|
|
MaskPermissionGrantingStrategy(AuditLogger auditLogger) {
|
|
MaskPermissionGrantingStrategy(AuditLogger auditLogger) {
|
|
super(auditLogger);
|
|
super(auditLogger);
|
|
}
|
|
}
|
|
@@ -611,26 +551,28 @@ public class AclImplTests {
|
|
}
|
|
}
|
|
return super.isGranted(ace, p);
|
|
return super.isGranted(ace, p);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
private class MockAclService implements MutableAclService {
|
|
private class MockAclService implements MutableAclService {
|
|
- public MutableAcl createAcl(ObjectIdentity objectIdentity)
|
|
|
|
- throws AlreadyExistsException {
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren)
|
|
|
|
- throws ChildrenExistException {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
* Mock implementation that populates the aces list with fully initialized
|
|
* Mock implementation that populates the aces list with fully initialized
|
|
* AccessControlEntries
|
|
* AccessControlEntries
|
|
*
|
|
*
|
|
- * @see
|
|
|
|
- * org.springframework.security.acls.MutableAclService#updateAcl(org.springframework
|
|
|
|
- * .security.acls.MutableAcl)
|
|
|
|
|
|
+ * @see org.springframework.security.acls.MutableAclService#updateAcl(org.
|
|
|
|
+ * springframework .security.acls.MutableAcl)
|
|
*/
|
|
*/
|
|
|
|
+ @Override
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
|
|
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
|
|
List<AccessControlEntry> oldAces = acl.getEntries();
|
|
List<AccessControlEntry> oldAces = acl.getEntries();
|
|
@@ -640,45 +582,47 @@ public class AclImplTests {
|
|
try {
|
|
try {
|
|
newAces = (List) acesField.get(acl);
|
|
newAces = (List) acesField.get(acl);
|
|
newAces.clear();
|
|
newAces.clear();
|
|
-
|
|
|
|
for (int i = 0; i < oldAces.size(); i++) {
|
|
for (int i = 0; i < oldAces.size(); i++) {
|
|
AccessControlEntry ac = oldAces.get(i);
|
|
AccessControlEntry ac = oldAces.get(i);
|
|
// Just give an ID to all this acl's aces, rest of the fields are just
|
|
// Just give an ID to all this acl's aces, rest of the fields are just
|
|
// copied
|
|
// copied
|
|
- newAces.add(new AccessControlEntryImpl((i + 1), ac.getAcl(), ac
|
|
|
|
- .getSid(), ac.getPermission(), ac.isGranting(),
|
|
|
|
- ((AuditableAccessControlEntry) ac).isAuditSuccess(),
|
|
|
|
|
|
+ newAces.add(new AccessControlEntryImpl((i + 1), ac.getAcl(), ac.getSid(), ac.getPermission(),
|
|
|
|
+ ac.isGranting(), ((AuditableAccessControlEntry) ac).isAuditSuccess(),
|
|
((AuditableAccessControlEntry) ac).isAuditFailure()));
|
|
((AuditableAccessControlEntry) ac).isAuditFailure()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- catch (IllegalAccessException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ catch (IllegalAccessException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
}
|
|
}
|
|
-
|
|
|
|
return acl;
|
|
return acl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
|
|
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
public Acl readAclById(ObjectIdentity object) throws NotFoundException {
|
|
public Acl readAclById(ObjectIdentity object) throws NotFoundException {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public Acl readAclById(ObjectIdentity object, List<Sid> sids)
|
|
|
|
- throws NotFoundException {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects)
|
|
|
|
- throws NotFoundException {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects) throws NotFoundException {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects,
|
|
|
|
- List<Sid> sids) throws NotFoundException {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects, List<Sid> sids)
|
|
|
|
+ throws NotFoundException {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|