use of org.eclipse.winery.accountability.model.authorization.AuthorizationInfo 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.AuthorizationInfo 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.AuthorizationInfo in project winery by eclipse.
the class AccountabilityManagerImpl method getHistory.
@Override
public CompletableFuture<List<FileProvenanceElement>> getHistory(String processIdentifier, String fileId) {
CompletableFuture<AuthorizationInfo> authorizationTree = this.blockchain.getAuthorizationTree(processIdentifier);
return this.blockchain.getProvenance(processIdentifier).thenCombine(authorizationTree, (provenanceElements, authorizationInfo) -> {
List<FileProvenanceElement> result;
if (authorizationInfo != null) {
result = getHistoryOfSingleFile(provenanceElements, fileId, authorizationInfo);
} else {
LOGGER.info(NO_AUTHORIZATION_DATA);
FileProvenanceElement historyElement = new FileProvenanceElement("", 0, NO_AUTHORIZATION_DATA);
historyElement.setAuthorized(false);
historyElement.setFileName(fileId);
result = Collections.singletonList(historyElement);
}
return result;
});
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationInfo in project winery by eclipse.
the class AccountabilityManagerImplIntegrationTest method addParticipant.
@Test
void addParticipant() throws Exception {
String processId = "ServiceTemplateWithAllReqCapVariants";
String participantBlockchainId = "0x0000000000000000000000000111111222223333";
String participantName = "Ghareeb";
CompletableFuture<String> authorize = this.accountabilityManager.authorize(processId, participantBlockchainId, participantName);
assertNotNull(authorize.get());
CompletableFuture<AuthorizationInfo> authorization = this.accountabilityManager.getAuthorization(processId);
AuthorizationInfo authorizationInfo = authorization.get();
assertTrue(authorizationInfo.isAuthorized(participantBlockchainId));
}
use of org.eclipse.winery.accountability.model.authorization.AuthorizationInfo 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;
}
Aggregations