use of org.exist.util.crypto.digest.MessageDigest in project exist by eXist-db.
the class BlobStoreRecoveryTest method addNoCommit.
/**
* Add Blob (DO NOT commit), then stop (either by shutdown or simulated crash).
*
* Expect that the Blob is NOT present after recovery.
*/
@Test
public void addNoCommit() throws IOException, BrokerPoolServiceException, EXistException {
final Path blobDbx = temporaryFolder.getRoot().toPath().resolve("blob.dbx");
final Path blobDir = temporaryFolder.newFolder("blob").toPath();
final Tuple2<byte[], MessageDigest> tempBin1 = generateTestFile();
// write the data
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
addNoCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
}
// test the recovery
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
final BlobId blobId = new BlobId(tempBin1._2.getValue());
final Tuple2<byte[], MessageDigest> actual = getCommit(blobDb.transactionManager, blobDb.blobStore, blobId);
assertNull(actual);
if (blobDb.blobStore instanceof BlobStoreImpl) {
assertNull(((BlobStoreImpl) blobDb.blobStore).getReferenceCount(blobId));
}
}
}
use of org.exist.util.crypto.digest.MessageDigest in project exist by eXist-db.
the class BlobStoreRecoveryTest method addCommit_addNoCommit.
/**
* Add Blob and commit, re-add same Blob (DO NOT commit), then stop (either by shutdown or simulated crash).
*
* Expect that the Blob is present after recovery.
*/
@Test
public void addCommit_addNoCommit() throws IOException, BrokerPoolServiceException, EXistException {
final Path blobDbx = temporaryFolder.getRoot().toPath().resolve("blob.dbx");
final Path blobDir = temporaryFolder.newFolder("blob").toPath();
final Tuple2<byte[], MessageDigest> tempBin1 = generateTestFile();
// write the data
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
addCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
addNoCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
}
// test the recovery
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
final BlobId blobId = new BlobId(tempBin1._2.getValue());
final Tuple2<byte[], MessageDigest> actual = getCommit(blobDb.transactionManager, blobDb.blobStore, blobId);
assertNotNull(actual);
assertEquals(tempBin1._2, tempBin1._2);
assertArrayEquals(tempBin1._1, tempBin1._1);
if (blobDb.blobStore instanceof BlobStoreImpl) {
assertEquals(1, ((BlobStoreImpl) blobDb.blobStore).getReferenceCount(blobId).intValue());
}
}
}
use of org.exist.util.crypto.digest.MessageDigest in project exist by eXist-db.
the class BlobStoreRecoveryTest method addCommit_addCommit_removeNoCommit.
/**
* Add Blob and commit, re-add same Blob and commit, Remove Blob (DO NOT commit), then stop (either by shutdown or simulated crash).
*
* Expect that the Blob is present after recovery.
*/
@Test
public void addCommit_addCommit_removeNoCommit() throws IOException, BrokerPoolServiceException, EXistException {
final Path blobDbx = temporaryFolder.getRoot().toPath().resolve("blob.dbx");
final Path blobDir = temporaryFolder.newFolder("blob").toPath();
final Tuple2<byte[], MessageDigest> tempBin1 = generateTestFile();
// write the data
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
addCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
addCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
removeNoCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
}
// test the recovery
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
final BlobId blobId = new BlobId(tempBin1._2.getValue());
final Tuple2<byte[], MessageDigest> actual = getCommit(blobDb.transactionManager, blobDb.blobStore, blobId);
assertNotNull(actual);
assertEquals(tempBin1._2, tempBin1._2);
assertArrayEquals(tempBin1._1, tempBin1._1);
if (blobDb.blobStore instanceof BlobStoreImpl) {
assertEquals(2, ((BlobStoreImpl) blobDb.blobStore).getReferenceCount(blobId).intValue());
}
}
}
use of org.exist.util.crypto.digest.MessageDigest in project exist by eXist-db.
the class BlobStoreRecoveryTest method addCommit_addCommit.
/**
* Add Blob and commit, re-add same Blob and commit, then stop (either by shutdown or simulated crash).
*
* Expect that the Blob is present after recovery.
*/
@Test
public void addCommit_addCommit() throws IOException, BrokerPoolServiceException, EXistException {
final Path blobDbx = temporaryFolder.getRoot().toPath().resolve("blob.dbx");
final Path blobDir = temporaryFolder.newFolder("blob").toPath();
final Tuple2<byte[], MessageDigest> tempBin1 = generateTestFile();
// write the data
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
addCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
addCommit(blobDb.transactionManager, blobDb.blobStore, tempBin1._1);
}
// test the recovery
try (final BlobDb blobDb = newBlobDb(temporaryFolder.getRoot().toPath(), blobDbx, blobDir)) {
blobDb.blobStore.open();
final BlobId blobId = new BlobId(tempBin1._2.getValue());
final Tuple2<byte[], MessageDigest> actual = getCommit(blobDb.transactionManager, blobDb.blobStore, blobId);
assertNotNull(actual);
assertEquals(tempBin1._2, tempBin1._2);
assertArrayEquals(tempBin1._1, tempBin1._1);
if (blobDb.blobStore instanceof BlobStoreImpl) {
assertEquals(2, ((BlobStoreImpl) blobDb.blobStore).getReferenceCount(blobId).intValue());
}
}
}
use of org.exist.util.crypto.digest.MessageDigest in project exist by eXist-db.
the class ClientFrame method setPermAction.
private void setPermAction(final ActionEvent ev) throws PermissionDeniedException {
if (fileman.getSelectedRowCount() == 0) {
return;
}
try {
final Collection collection = client.getCollection();
final UserManagementService service = getUserManagementService();
String name = null;
String created = null;
String modified = null;
String size = null;
String messageDigestType = null;
String messageDigestValue = null;
String mimeType = null;
String owner = null;
String group = null;
ModeDisplay mode = null;
SimpleACLPermissionAider acl = null;
final DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
final List<ResourceDescriptor> selected = new ArrayList<>();
boolean firstPerm = true;
for (final int row : fileman.getSelectedRows()) {
final ResourceDescriptor selectedRow = resources.getRow(row);
selected.add(selectedRow);
final XmldbURI thisName = selectedRow.getName();
final String thisCreated;
final String thisModified;
final String thisMessageDigestType;
final String thisMessageDigestValue;
final String thisSize;
final String thisMimeType;
final Permission thisPerm;
if (selectedRow.isCollection()) {
final Collection coll = collection.getChildCollection(thisName.toString());
thisCreated = dateTimeFormat.format(((EXistCollection) coll).getCreationTime());
thisModified = NON_APPLICABLE;
thisMimeType = COLLECTION_MIME_TYPE;
thisMessageDigestType = NON_APPLICABLE;
thisMessageDigestValue = NON_APPLICABLE;
thisSize = NON_APPLICABLE;
thisPerm = service.getPermissions(coll);
} else {
final Resource res = collection.getResource(thisName.toString());
thisCreated = dateTimeFormat.format(((EXistResource) res).getCreationTime());
thisModified = dateTimeFormat.format(((EXistResource) res).getLastModificationTime());
thisMimeType = ((EXistResource) res).getMimeType();
if (res instanceof EXistBinaryResource) {
final MessageDigest messageDigest = ((EXistBinaryResource) res).getContentDigest(DigestType.BLAKE_256);
thisMessageDigestType = messageDigest.getDigestType().getCommonNames()[0];
thisMessageDigestValue = messageDigest.toHexString();
thisSize = humanSize(((EXistBinaryResource) res).getContentLength());
} else {
thisMessageDigestType = NON_APPLICABLE;
thisMessageDigestValue = NON_APPLICABLE;
thisSize = NON_APPLICABLE;
}
thisPerm = service.getPermissions(res);
}
name = getUpdated(name, () -> URIUtils.urlDecodeUtf8(thisName));
created = getUpdated(created, thisCreated);
modified = getUpdated(modified, thisModified);
mimeType = getUpdated(mimeType, thisMimeType);
messageDigestType = getUpdated(messageDigestType, thisMessageDigestType);
messageDigestValue = getUpdated(messageDigestValue, thisMessageDigestValue);
size = getUpdated(size, thisSize);
owner = getUpdated(owner, () -> thisPerm.getOwner().getName());
group = getUpdated(group, () -> thisPerm.getGroup().getName());
mode = getUpdatedMode(mode, thisPerm);
if (firstPerm) {
if (thisPerm instanceof ACLPermission) {
final ACLPermission thisAcl = (ACLPermission) thisPerm;
acl = new SimpleACLPermissionAider();
for (int i = 0; i < thisAcl.getACECount(); i++) {
acl.addACE(thisAcl.getACEAccessType(i), thisAcl.getACETarget(i), thisAcl.getACEWho(i), thisAcl.getACEMode(i));
}
} else {
acl = null;
}
firstPerm = false;
} else {
if (acl != null && thisPerm instanceof ACLPermission) {
final ACLPermission thisAcl = (ACLPermission) thisPerm;
if (!acl.aclEquals(thisAcl)) {
acl = null;
}
}
}
}
final EditPropertiesDialog editPropertiesDialog = new EditPropertiesDialog(service, client.getProperties().getProperty(InteractiveClient.USER), collection, name, mimeType, created, modified, size, messageDigestType, messageDigestValue, owner, group, mode, acl, selected);
editPropertiesDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(final WindowEvent e) {
try {
client.reloadCollection();
} catch (final XMLDBException xmldbe) {
// $NON-NLS-1$
showErrorMessage(Messages.getString("ClientFrame.197") + xmldbe.getMessage(), xmldbe);
xmldbe.printStackTrace();
}
}
});
editPropertiesDialog.setVisible(true);
} catch (final XMLDBException e) {
// $NON-NLS-1$
showErrorMessage(Messages.getString("ClientFrame.197") + e.getMessage(), e);
e.printStackTrace();
}
}
Aggregations