Search in sources :

Example 26 with DBBroker

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));
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) Test(org.junit.Test)

Example 27 with DBBroker

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) Test(org.junit.Test)

Example 28 with DBBroker

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Test(org.junit.Test)

Example 29 with DBBroker

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;
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 30 with DBBroker

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);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

DBBroker (org.exist.storage.DBBroker)468 BrokerPool (org.exist.storage.BrokerPool)304 Txn (org.exist.storage.txn.Txn)219 Sequence (org.exist.xquery.value.Sequence)185 Test (org.junit.Test)170 XQuery (org.exist.xquery.XQuery)108 Collection (org.exist.collections.Collection)93 TransactionManager (org.exist.storage.txn.TransactionManager)70 EXistException (org.exist.EXistException)66 StringInputSource (org.exist.util.StringInputSource)66 PermissionDeniedException (org.exist.security.PermissionDeniedException)44 Source (org.exist.source.Source)42 StringSource (org.exist.source.StringSource)41 XmldbURI (org.exist.xmldb.XmldbURI)41 CompiledXQuery (org.exist.xquery.CompiledXQuery)39 IOException (java.io.IOException)38 QName (org.exist.dom.QName)37 LockedDocument (org.exist.dom.persistent.LockedDocument)36 Database (org.exist.Database)35 XPathException (org.exist.xquery.XPathException)30