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());
}
}
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);
}
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();
}
}
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));
});
}
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));
});
}
Aggregations