use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method add.
@Test
public void add() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
assertEquals(0, permission.getACECount());
final int userId = 1;
final int mode = ALL;
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, userId, mode);
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
assertEquals(1, permission.getACECount());
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(userId, permission.getACEId(0));
assertEquals(mode, permission.getACEMode(0));
}
use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method validate_read_when_readInACL.
@Test
public void validate_read_when_readInACL() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true);
final int ownerId = new Random().nextInt(SecurityManagerImpl.MAX_USER_ID);
final int mode = 0700;
final int ownerGroupId = new Random().nextInt(SecurityManagerImpl.MAX_GROUP_ID);
final Subject mockUser = EasyMock.createMock(Subject.class);
final boolean mockUserHasDbaRole = false;
final int mockUserId = new Random().nextInt(SecurityManagerImpl.MAX_USER_ID);
expect(mockUser.hasDbaRole()).andReturn(mockUserHasDbaRole);
expect(mockUser.getId()).andReturn(mockUserId);
expect(mockUser.getGroupIds()).andReturn(new int[0]);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockUser);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager, ownerId, ownerGroupId, mode);
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, mockUserId, Permission.READ);
boolean isValid = permission.validate(mockUser, Permission.READ);
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockUser);
assertTrue(isValid);
}
use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method insert_atFront_whenEmpty.
@Test
public void insert_atFront_whenEmpty() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
assertEquals(0, permission.getACECount());
final int userId = 1112;
final int mode = ALL;
permission.insertUserACE(0, ACE_ACCESS_TYPE.ALLOWED, userId, mode);
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
assertEquals(1, permission.getACECount());
assertEquals(userId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(ALL, permission.getACEMode(0));
}
use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method validate_can_write_ACL_ordered_entries.
@Test
public void validate_can_write_ACL_ordered_entries() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(2);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(2);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(2);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true).times(2);
final int ownerId = new Random().nextInt(SecurityManagerImpl.MAX_USER_ID);
final int mode = 0700;
final int ownerGroupId = new Random().nextInt(SecurityManagerImpl.MAX_GROUP_ID);
/**
* We create ACE entries which has -
* 1) user "userA" who is DENIED READ access
* 2) group "groupA" who is ALLOWED WRITE access
*
* userA is a member of groupA, and so should still be ALLOWED write access
* as the ACL is evaluated top-down
*/
final Subject mockUser = EasyMock.createMock(Subject.class);
final boolean mockUserHasDbaRole = false;
final int mockUserId = new Random().nextInt(SecurityManagerImpl.MAX_USER_ID);
final int mockGroupId = new Random().nextInt(SecurityManagerImpl.MAX_GROUP_ID);
expect(mockUser.hasDbaRole()).andReturn(mockUserHasDbaRole);
expect(mockUser.getId()).andReturn(mockUserId);
expect(mockUser.getGroupIds()).andReturn(new int[] { mockGroupId });
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockUser);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager, ownerId, ownerGroupId, mode);
permission.addUserACE(ACE_ACCESS_TYPE.DENIED, mockUserId, Permission.READ);
permission.addGroupACE(ACE_ACCESS_TYPE.ALLOWED, mockGroupId, Permission.WRITE);
boolean isValid = permission.validate(mockUser, Permission.WRITE);
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockUser);
assertTrue(isValid);
}
use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method insert_inMiddle.
@Test
public void insert_inMiddle() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(3);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(3);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(3);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true).times(3);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
assertEquals(0, permission.getACECount());
final int userId = 1112;
final int mode = ALL;
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, userId, mode);
assertEquals(1, permission.getACECount());
assertEquals(userId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(ALL, permission.getACEMode(0));
final int secondUserId = 1113;
final int secondMode = 04;
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, secondUserId, secondMode);
assertEquals(2, permission.getACECount());
assertEquals(secondUserId, permission.getACEId(1));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(1));
assertEquals(ACE_TARGET.USER, permission.getACETarget(1));
assertEquals(secondMode, permission.getACEMode(1));
final int thirdUserId = 1114;
final int thirdMode = 02;
permission.insertUserACE(1, ACE_ACCESS_TYPE.ALLOWED, thirdUserId, thirdMode);
assertEquals(3, permission.getACECount());
assertEquals(userId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(ALL, permission.getACEMode(0));
assertEquals(thirdUserId, permission.getACEId(1));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(1));
assertEquals(ACE_TARGET.USER, permission.getACETarget(1));
assertEquals(thirdMode, permission.getACEMode(1));
assertEquals(secondUserId, permission.getACEId(2));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(2));
assertEquals(ACE_TARGET.USER, permission.getACETarget(2));
assertEquals(secondMode, permission.getACEMode(2));
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
}
Aggregations