use of org.eclipse.winery.accountability.model.authorization.AuthorizationElement in project winery by eclipse.
the class AccountabilityManagerImplTest method verifyManifestArguments.
private static Stream<Arguments> verifyManifestArguments() {
String validState = "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n";
ModelProvenanceElement validElement = new ModelProvenanceElement();
validElement.setFingerprint(validState);
validElement.setAuthorAddress("0x11111");
ModelProvenanceElement invalidElement = new ModelProvenanceElement();
invalidElement.setFingerprint("Empty");
invalidElement.setAuthorAddress("0x11111");
ModelProvenanceElement unauthorizedElement = new ModelProvenanceElement();
unauthorizedElement.setFingerprint("TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n");
unauthorizedElement.setAuthorAddress("0x11234111");
AuthorizationElement authorizationElement = new AuthorizationElement();
authorizationElement.setAuthorizerBlockchainAddress("0x11111");
authorizationElement.setAuthorizedBlockchainAddress("0x11111");
authorizationElement.setAuthorizedIdentity("Gharreb");
authorizationElement.setTransactionHash("0x3215F23");
List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
return Stream.of(Arguments.of(validElement, VERIFIED, authorizationInfo, "Expect a verified manifest"), Arguments.of(invalidElement, INVALID, authorizationInfo, "Expect an invalid manifest"), Arguments.of(null, NO_MANIFEST_FILE_IN_PROVENANCE_LAYER, authorizationInfo, "Expect no manifest in provenance"), Arguments.of(unauthorizedElement, UNAUTHORIZED, authorizationInfo, "Expect a unauthorized manifest"));
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationElement in project winery by eclipse.
the class AccountabilityManagerImplTest method getHistoryOfSingleFileArguments.
private static Stream<Arguments> getHistoryOfSingleFileArguments() {
String fileId = "folder/myFile.tosca";
ModelProvenanceElement elementWithFileOccurrence_0 = new ModelProvenanceElement("0x1000000000000000000000000000000000000000", 0, "0x11111", // region string
"TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
ModelProvenanceElement elementWithFileOccurrence_1 = new ModelProvenanceElement("0x2000000000000000000000000000000000000000", 0, "0x3333", // region string
"TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
ModelProvenanceElement elementWithoutFileOccurrence_0 = new ModelProvenanceElement("0x3000000000000000000000000000000000000000", 0, "0x11111", // region string
"TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: Definitions/myTestFile1.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
AuthorizationElement authorizationElement = new AuthorizationElement();
authorizationElement.setAuthorizerBlockchainAddress("0x11111");
authorizationElement.setAuthorizedBlockchainAddress("0x11111");
authorizationElement.setAuthorizedIdentity("Gharreb");
authorizationElement.setTransactionHash("0x3215F230003215F230003215F230003215F23000");
List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
return Stream.of(Arguments.of(null, "someId", null, authorizationInfo, null, "Empty provenance elements list"), Arguments.of(Arrays.asList(elementWithFileOccurrence_0, elementWithoutFileOccurrence_0, elementWithFileOccurrence_1), fileId, Arrays.asList(new FileProvenanceElement(elementWithFileOccurrence_0), new FileProvenanceElement(elementWithFileOccurrence_1)), authorizationInfo, new boolean[] { true, false }, "Find two file occurrences"));
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationElement in project winery by eclipse.
the class AuthorizationSmartContractWrapper method getAuthorizationTree.
/**
* Retrieves the {@link AuthorizationInfo} from the blockchain.
* If no authorization data can be retrieved, the completable future returns <code>null</code>.
*
* @param identifier The process identifier identifying the collaboration process.
* @return A completable future containing the authorization information.
*/
public CompletableFuture<AuthorizationInfo> getAuthorizationTree(final String identifier) {
// eventName, indexed parameters, unindexed parameters
final Event event = new Event("Authorized", Arrays.asList(new TypeReference<Utf8String>() {
}, new TypeReference<Address>() {
}, new TypeReference<Address>() {
}, new TypeReference<Utf8String>() {
}));
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contract.getContractAddress()).addSingleTopic(EventEncoder.encode(event)).addOptionalTopics(Hash.sha3String(identifier)).addNullTopic().addNullTopic();
final CompletableFuture<AuthorizationInfo> result = new CompletableFuture<>();
try {
final int recordsCount = web3j.ethGetLogs(filter).send().getLogs().size();
LOGGER.info(recordsCount + " authorization elements detected.");
if (recordsCount > 0) {
final List<AuthorizationElement> authorizationElements = new ArrayList<>();
final Disposable subscription = ((Authorization) contract).authorizedEventFlowable(filter).subscribe(authorizedEventResponse -> {
try {
final AuthorizationElement currentElement = generateAuthorizationElement(authorizedEventResponse);
authorizationElements.add(currentElement);
if (authorizationElements.size() == recordsCount) {
final AuthorizationTree tree = new AuthorizationTree(authorizationElements);
result.complete(tree);
}
} catch (EthereumException e) {
result.completeExceptionally(e);
}
});
// unsubscribe the observable when the CompletableFuture completes (this frees threads)
result.whenComplete((r, e) -> subscription.dispose());
} else {
// empty result
result.complete(null);
}
} catch (IOException e) {
final String msg = "Failed detecting the number of authorization elements for the collaboration resource. Reason: " + e.getMessage();
LOGGER.error(msg);
result.completeExceptionally(new EthereumException(msg, e));
}
return result;
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationElement in project winery by eclipse.
the class AuthorizationSmartContractWrapper method generateAuthorizationElement.
private AuthorizationElement generateAuthorizationElement(final Authorization.AuthorizedEventResponse event) throws EthereumException {
try {
final Log log = event.log;
final AuthorizationElement result = new AuthorizationElement();
result.setTransactionHash(log.getTransactionHash());
// get the timestamp of the block that includes the tx that includes the authorization record
result.setUnixTimestamp(web3j.ethGetBlockByHash(log.getBlockHash(), false).send().getBlock().getTimestamp().longValue());
result.setAuthorizerBlockchainAddress(event._authorizer);
result.setAuthorizedBlockchainAddress(event._authorized);
result.setAuthorizedIdentity(event.realWorldIdentity);
return result;
} catch (IOException e) {
final String msg = "Error while fetching block timestamp. Reason: " + e.getMessage();
LOGGER.error(msg);
throw new EthereumException(msg, e);
}
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationElement in project winery by eclipse.
the class AccountabilityManagerImplTest method validateBlockchainInputArguments.
private static Stream<Arguments> validateBlockchainInputArguments() throws Exception {
String manifestFile = "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n";
ModelProvenanceElement element = new ModelProvenanceElement();
element.setFingerprint(manifestFile);
element.setAuthorAddress("0x11111");
Map<String, File> validFilesHashMap = new HashMap<>();
validFilesHashMap.put("myTestFile.tosca", new File(ClassLoader.getSystemClassLoader().getResource("emptyDefinition.tosca").toURI()));
validFilesHashMap.put("myTestFile2.tosca", new File(ClassLoader.getSystemClassLoader().getResource("secondDefinition.tosca").toURI()));
validFilesHashMap.put("Tosca.meta", new File(ClassLoader.getSystemClassLoader().getResource("Tosca.meta").toURI()));
AuthorizationElement authorizationElement = new AuthorizationElement();
authorizationElement.setAuthorizerBlockchainAddress("0x11111");
authorizationElement.setAuthorizedBlockchainAddress("0x11111");
authorizationElement.setAuthorizedIdentity("Gharreb");
authorizationElement.setTransactionHash("0x3215F23");
List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
return Stream.of(Arguments.of(VERIFIED, Collections.singletonList(element), validFilesHashMap, authorizationInfo, "Simple valid file in manifest"));
}
Aggregations