use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class OAESEncryptionTest method testCreatedAESEncryptedDatabase.
public void testCreatedAESEncryptedDatabase() {
String buildDirectory = System.getProperty("buildDirectory", ".");
final String dbPath = buildDirectory + File.separator + DBNAME_DATABASETEST;
OFileUtils.deleteRecursively(new File(dbPath));
final ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "aes");
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");
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.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);
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.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();
if (db.isClosed())
db.open("admin", "admin");
db.drop();
}
}
use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class ODESEncryptionTest method testCreatedDESEncryptedCluster.
public void testCreatedDESEncryptedCluster() {
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 class TestEncryption encryption des")).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());
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
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"));
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
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();
if (db.exists())
db.drop();
}
}
use of com.orientechnologies.orient.core.exception.OSecurityException 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.exception.OSecurityException in project orientdb by orientechnologies.
the class OrientGraphFactoryEncryptionTest method verifyDatabaseEncryption.
public void verifyDatabaseEncryption(OrientGraphFactory fc) {
ODatabaseDocumentTx db = fc.getDatabase();
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 = fc.getDatabase();
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = fc.getDatabase();
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db = fc.getDatabase();
db.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db = fc.getDatabase();
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = fc.getDatabase();
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
}
Aggregations