use of org.exist.storage.DBBroker in project exist by eXist-db.
the class SimpleACLPermissionTest method addACE_ForGroupWithModeString.
@Test
public void addACE_ForGroupWithModeString() 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);
final Group mockGroup = EasyMock.createMock(Group.class);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
assertEquals(0, permission.getACECount());
final int groupId = 1112;
final String groupName = "aretter";
final String mode = "rwx";
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true);
expect(mockSecurityManager.getGroup(groupName)).andReturn(mockGroup);
expect(mockGroup.getId()).andReturn(groupId);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockGroup);
permission.addACE(ACE_ACCESS_TYPE.ALLOWED, ACE_TARGET.GROUP, groupName, mode);
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject, mockGroup);
assertEquals(1, permission.getACECount());
assertEquals(groupId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.GROUP, permission.getACETarget(0));
assertEquals(ALL, permission.getACEMode(0));
assertEquals(mode, permission.getACEModeString(0));
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class SimpleACLPermissionTest method clear.
@Test
public void clear() 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());
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, 1, ALL);
final int secondUserId = 2;
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, secondUserId, ALL);
assertEquals(2, permission.getACECount());
permission.clear();
assertEquals(0, permission.getACECount());
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AbstractGroupTest method assertCanModifyGroup_succeeds_when_user_is_dba.
@Test
public void assertCanModifyGroup_succeeds_when_user_is_dba() throws PermissionDeniedException, ConfigurationException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createMock(AbstractRealm.class);
Account mockAccount = EasyMock.createMock(Account.class);
TestableGroupImpl group = new TestableGroupImpl(mockBroker, mockRealm);
// expectations
expect(mockAccount.hasDbaRole()).andReturn(Boolean.TRUE);
replay(mockAccount);
// test
group.assertCanModifyGroup(mockAccount);
verify(mockAccount);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class FnDocSecurityTest method cannotAccessRestrictedDocument.
@Test(expected = PermissionDeniedException.class)
public void cannotAccessRestrictedDocument() throws EXistException, AuthenticationException, PermissionDeniedException, XPathException, IOException, SAXException {
// as docTestUser1 user
final String query = "fn:doc('" + TEST_DOC_URI_SYSTEM_ONLY + "')";
final BrokerPool pool = server.getBrokerPool();
final SecurityManager securityManager = pool.getSecurityManager();
final Subject testUser1 = securityManager.authenticate(TEST_USER_1, TEST_USER_1);
try (final DBBroker broker = pool.get(Optional.of(testUser1));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final XQuery xqueryService = pool.getXQueryService();
final Sequence result = xqueryService.execute(broker, query, null);
fail("Expected PermissionDeniedException via XPathException");
transaction.commit();
} catch (final XPathException e) {
if (e.getCause() != null && e.getCause() instanceof PermissionDeniedException) {
throw (PermissionDeniedException) e.getCause();
} else {
throw e;
}
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class DatabaseInsertResources_WithValidation_Test method removeTestCollections.
private static void removeTestCollections() throws Exception {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(ADMIN_DB_USER, ADMIN_DB_PWD)));
final Txn txn = transact.beginTransaction()) {
Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI));
broker.removeCollection(txn, testCollection);
transact.commit(txn);
}
}
Aggregations