Search in sources :

Example 31 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class SecurityManagerImpl method attach.

/**
 * Initialize the security manager.
 *
 * Checks if the file users.xml exists in the system collection of the database.
 * If not, it is created with two default users: admin and guest.
 *
 * @param broker the database broker
 */
@Override
public void attach(final DBBroker broker, final Txn transaction) throws EXistException {
    // TODO: check that db is same?
    db = broker.getDatabase();
    Collection systemCollection = null;
    try {
        systemCollection = broker.getCollection(XmldbURI.SYSTEM_COLLECTION_URI);
        if (systemCollection == null) {
            systemCollection = broker.getOrCreateCollection(transaction, XmldbURI.SYSTEM_COLLECTION_URI);
            if (systemCollection == null) {
                return;
            }
            systemCollection.setPermissions(broker, Permission.DEFAULT_SYSTEM_COLLECTION_PERM);
            broker.saveCollection(transaction, systemCollection);
        }
    } catch (final Exception e) {
        LOG.error("Setting /db/system permissions failed: {}", e.getMessage(), e);
    }
    try {
        collection = broker.getCollection(SECURITY_COLLECTION_URI);
        if (collection == null) {
            collection = broker.getOrCreateCollection(transaction, SECURITY_COLLECTION_URI);
            if (collection == null) {
                LOG.error("Collection '/db/system/security' can't be created. Database may be corrupt!");
                return;
            }
            collection.setPermissions(broker, Permission.DEFAULT_SYSTEM_SECURITY_COLLECTION_PERM);
            broker.saveCollection(transaction, collection);
        }
    } catch (final Exception e) {
        e.printStackTrace();
        LOG.error("Loading security configuration failed: {}", e.getMessage(), e);
    }
    final Configuration _config_ = Configurator.parse(this, broker, collection, CONFIG_FILE_URI);
    configuration = Configurator.configure(this, _config_);
    for (final Realm realm : realms) {
        realm.start(broker, transaction);
    }
}
Also used : Configuration(org.exist.config.Configuration) Collection(org.exist.collections.Collection) AbstractRealm(org.exist.security.AbstractRealm) Realm(org.exist.security.realm.Realm) ConfigurationException(org.exist.config.ConfigurationException) PermissionDeniedException(org.exist.security.PermissionDeniedException) AuthenticationException(org.exist.security.AuthenticationException) BrokerPoolServiceException(org.exist.storage.BrokerPoolServiceException) EXistException(org.exist.EXistException)

Example 32 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class IndexerTest2 method storeDoc.

private static void storeDoc() throws PermissionDeniedException, IOException, EXistException, SAXException, LockException, AuthenticationException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager txnMgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate("admin", "")));
        final Txn txn = txnMgr.beginTransaction()) {
        try (final Collection collection = broker.getOrCreateCollection(txn, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(txn, TestConstants.TEST_XML_URI2, new StringInputSource(XML), MimeType.XML_TYPE, collection);
            broker.flush();
            broker.saveCollection(txn, collection);
        }
        txnMgr.commit(txn);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 33 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class SystemExportImportTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, test, COLLECTION_CONFIG);
        broker.storeDocument(transaction, doc01uri.lastSegment(), new StringInputSource(XML1), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc02uri.lastSegment(), new StringInputSource(XML2), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc03uri.lastSegment(), new StringInputSource(XML3), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc11uri.lastSegment(), new StringInputSource(BINARY.getBytes(UTF_8)), MimeType.BINARY_TYPE, test);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 34 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class Modification method prepareTrigger.

/**
 * Fires the prepare function for the UPDATE_DOCUMENT_EVENT trigger for the Document doc
 *
 * @param transaction The database transaction
 * @param doc The document to trigger for
 *
 * @throws TriggerException if a trigger raises an error
 */
private void prepareTrigger(Txn transaction, DocumentImpl doc) throws TriggerException {
    final Collection col = doc.getCollection();
    final DocumentTrigger trigger = new DocumentTriggers(broker, transaction, col);
    trigger.beforeUpdateDocument(broker, transaction, doc);
    triggers.put(doc.getDocId(), trigger);
}
Also used : Collection(org.exist.collections.Collection) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) DocumentTriggers(org.exist.collections.triggers.DocumentTriggers)

Example 35 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class IndexerTest method store_preserve_ws_mixed_content_value.

private void store_preserve_ws_mixed_content_value(final boolean propValue, final String xml) throws PermissionDeniedException, IOException, EXistException, SAXException, LockException, AuthenticationException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    pool.getConfiguration().setProperty(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT, propValue);
    final TransactionManager txnMgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate("admin", "")));
        final Txn txn = txnMgr.beginTransaction()) {
        try (final Collection collection = broker.getOrCreateCollection(txn, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(txn, TestConstants.TEST_XML_URI, new StringInputSource(xml), MimeType.XML_TYPE, collection);
            broker.flush();
            broker.saveCollection(txn, collection);
        }
        txnMgr.commit(txn);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

Collection (org.exist.collections.Collection)297 Txn (org.exist.storage.txn.Txn)160 XmldbURI (org.exist.xmldb.XmldbURI)99 DBBroker (org.exist.storage.DBBroker)89 TransactionManager (org.exist.storage.txn.TransactionManager)86 BrokerPool (org.exist.storage.BrokerPool)69 StringInputSource (org.exist.util.StringInputSource)57 Test (org.junit.Test)57 EXistException (org.exist.EXistException)43 PermissionDeniedException (org.exist.security.PermissionDeniedException)43 DocumentImpl (org.exist.dom.persistent.DocumentImpl)42 IOException (java.io.IOException)33 LockedDocument (org.exist.dom.persistent.LockedDocument)31 SAXException (org.xml.sax.SAXException)26 InputStream (java.io.InputStream)19 Path (java.nio.file.Path)19 Permission (org.exist.security.Permission)19 LockException (org.exist.util.LockException)16 TriggerException (org.exist.collections.triggers.TriggerException)15 BinaryDocument (org.exist.dom.persistent.BinaryDocument)15