Search in sources :

Example 41 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class TransformTest method xslDocument.

@Ignore("https://github.com/eXist-db/exist/issues/2096")
@Test
public void xslDocument() throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final XQuery xquery = pool.getXQueryService();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Sequence sequence = xquery.execute(broker, DOCUMENT_XSLT_QUERY, null);
        assertNotNull(sequence);
        assertTrue(sequence.hasOne());
        final Item item = sequence.itemAt(0);
        assertEquals(Type.DOCUMENT, item.getType());
        final Source expected = Input.fromString("<elem1/>").build();
        final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Document.class)).build();
        final Diff diff = DiffBuilder.compare(actual).withTest(expected).checkForSimilar().build();
        assertFalse(diff.toString(), diff.hasDifferences());
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) Diff(org.xmlunit.diff.Diff) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source)

Example 42 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method xqueryRemoveUserFromGroup.

private Sequence xqueryRemoveUserFromGroup(final String username, final String groupname) throws XPathException, PermissionDeniedException, EXistException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final Optional<Subject> asUser = Optional.of(pool.getSecurityManager().getSystemSubject());
    return xqueryRemoveUserFromGroup(username, groupname, asUser);
}
Also used : BrokerPool(org.exist.storage.BrokerPool)

Example 43 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method setup.

@Before
public void setup() throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    // create user with personal group as primary group
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = createUser(broker, sm, USER1_NAME, USER1_PWD);
        final Group otherGroup1 = createGroup(broker, sm, OTHER_GROUP1_NAME);
        addUserToGroup(sm, user1, otherGroup1);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP1_NAME);
        final Group otherGroup2 = createGroup(broker, sm, OTHER_GROUP2_NAME);
        addUserToGroup(sm, user1, otherGroup2);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP2_NAME);
        transaction.commit();
    }
    // check that the user is as we expect
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = sm.getAccount(USER1_NAME);
        assertEquals(USER1_NAME, user1.getPrimaryGroup());
        final String[] user1Groups = user1.getGroups();
        assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
        for (final String user1Group : user1Groups) {
            assertNotNull(sm.getGroup(user1Group));
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) Before(org.junit.Before)

Example 44 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method cannotRemoveAllGroupsFromUserAsDBA.

@Test(expected = PermissionDeniedException.class)
public void cannotRemoveAllGroupsFromUserAsDBA() throws XPathException, PermissionDeniedException, EXistException, AuthenticationException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final Subject admin = pool.getSecurityManager().authenticate(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    extractPermissionDenied(() -> {
        xqueryRemoveUserFromGroup(USER1_NAME, OTHER_GROUP2_NAME, Optional.of(admin));
        xqueryRemoveUserFromGroup(USER1_NAME, OTHER_GROUP1_NAME, Optional.of(admin));
        xqueryRemoveUserFromGroup(USER1_NAME, USER1_NAME, Optional.of(admin));
    });
}
Also used : BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 45 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method cannotRemoveAllGroupsFromUserAsOwner.

@Test(expected = PermissionDeniedException.class)
public void cannotRemoveAllGroupsFromUserAsOwner() throws XPathException, PermissionDeniedException, EXistException, AuthenticationException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final Subject owner = pool.getSecurityManager().authenticate(USER1_NAME, USER1_NAME);
    extractPermissionDenied(() -> {
        xqueryRemoveUserFromGroup(USER1_NAME, OTHER_GROUP2_NAME, Optional.of(owner));
        xqueryRemoveUserFromGroup(USER1_NAME, OTHER_GROUP1_NAME, Optional.of(owner));
        xqueryRemoveUserFromGroup(USER1_NAME, USER1_NAME, Optional.of(owner));
    });
}
Also used : BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Aggregations

BrokerPool (org.exist.storage.BrokerPool)381 DBBroker (org.exist.storage.DBBroker)300 Txn (org.exist.storage.txn.Txn)180 Sequence (org.exist.xquery.value.Sequence)157 Test (org.junit.Test)115 XQuery (org.exist.xquery.XQuery)105 Collection (org.exist.collections.Collection)71 StringInputSource (org.exist.util.StringInputSource)66 TransactionManager (org.exist.storage.txn.TransactionManager)61 Source (org.exist.source.Source)43 StringSource (org.exist.source.StringSource)40 CompiledXQuery (org.exist.xquery.CompiledXQuery)38 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)21 XPathException (org.exist.xquery.XPathException)21 Properties (java.util.Properties)20 LockedDocument (org.exist.dom.persistent.LockedDocument)20 InputSource (org.xml.sax.InputSource)20 IOException (java.io.IOException)19 XQueryContext (org.exist.xquery.XQueryContext)19