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