use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class ONothingEncryptionTest method testCreatedNothingEncryptedDatabase.
public void testCreatedNothingEncryptedDatabase() {
OFileUtils.deleteRecursively(new File("target/" + DBNAME_DATABASETEST));
final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_DATABASETEST);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "des");
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.create();
try {
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
db.open("admin", "admin");
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
} finally {
db.activateOnCurrentThread();
db.drop();
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class ONothingEncryptionTest method testCreatedNothingEncryptedCluster.
public void testCreatedNothingEncryptedCluster() {
OFileUtils.deleteRecursively(new File("target/" + DBNAME_CLUSTERTEST));
final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_CLUSTERTEST);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.create();
try {
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("alter cluster TestEncryption encryption nothing")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
db.open("admin", "admin");
db.close();
Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
result = db.query(new OSQLSynchQuery<ODocument>("select from OUser"));
Assert.assertFalse(result.isEmpty());
} finally {
db.close();
Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
} finally {
db.close();
Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
} finally {
db.activateOnCurrentThread();
db.drop();
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OConfigurableHooksManager method onOpen.
public void onOpen(ODatabaseInternal iDatabase) {
if (!iDatabase.getStorage().isRemote()) {
final ODatabase<?> db = (ODatabase<?>) iDatabase;
for (OServerHookConfiguration hook : configuredHooks) {
try {
final ORecordHook.HOOK_POSITION pos = ORecordHook.HOOK_POSITION.valueOf(hook.position);
final ORecordHook h = (ORecordHook) Class.forName(hook.clazz).newInstance();
if (hook.parameters != null && hook.parameters.length > 0)
try {
final Method m = h.getClass().getDeclaredMethod("config", new Class[] { OServerParameterConfiguration[].class });
m.invoke(h, new Object[] { hook.parameters });
} catch (Exception e) {
OLogManager.instance().warn(this, "[configure] Failed to configure hook '%s'. Parameters specified but hook don support parameters. Should have a method config with parameters OServerParameterConfiguration[] ", hook.clazz);
}
db.registerHook(h, pos);
} catch (Exception e) {
OLogManager.instance().error(this, "[configure] Failed to configure hook '%s' due to the an error : ", e, hook.clazz, e.getMessage());
}
}
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OBaseGraphWorkload method getGraph.
protected OrientGraph getGraph(final ODatabaseIdentifier databaseIdentifier) {
final ODatabase database = ODatabaseUtils.openDatabase(databaseIdentifier, connectionStrategy);
if (database == null)
throw new IllegalArgumentException("Error on opening database " + databaseIdentifier.getName());
database.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, connectionStrategy.toString());
final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database);
g.setAutoStartTx(false);
return g;
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OCRUDWorkload method createSchema.
protected void createSchema(ODatabaseIdentifier databaseIdentifier) {
final ODatabase database = getDocumentDatabase(databaseIdentifier, OStorageRemote.CONNECTION_STRATEGY.STICKY);
try {
final OSchema schema = database.getMetadata().getSchema();
if (!schema.existsClass(OCRUDWorkload.CLASS_NAME)) {
final OClass cls = schema.createClass(OCRUDWorkload.CLASS_NAME);
cls.createProperty("name", OType.STRING);
// cls.createIndex(INDEX_NAME, OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString(), "name");
cls.createIndex(INDEX_NAME, OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "name" });
}
} finally {
database.close();
}
}
Aggregations