Search in sources :

Example 1 with AuthorizationInfo

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"));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)

Example 2 with AuthorizationInfo

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"));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 3 with AuthorizationInfo

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;
    });
}
Also used : AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 4 with AuthorizationInfo

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));
}
Also used : AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) Test(org.junit.jupiter.api.Test)

Example 5 with AuthorizationInfo

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;
}
Also used : Disposable(io.reactivex.disposables.Disposable) EthFilter(org.web3j.protocol.core.methods.request.EthFilter) ArrayList(java.util.ArrayList) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) IOException(java.io.IOException) Utf8String(org.web3j.abi.datatypes.Utf8String) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) CompletableFuture(java.util.concurrent.CompletableFuture) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) Event(org.web3j.abi.datatypes.Event) EthereumException(org.eclipse.winery.accountability.exceptions.EthereumException) TypeReference(org.web3j.abi.TypeReference)

Aggregations

AuthorizationInfo (org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)6 AuthorizationElement (org.eclipse.winery.accountability.model.authorization.AuthorizationElement)4 AuthorizationTree (org.eclipse.winery.accountability.model.authorization.AuthorizationTree)4 ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)3 FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)2 Disposable (io.reactivex.disposables.Disposable)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 EthereumException (org.eclipse.winery.accountability.exceptions.EthereumException)1 Test (org.junit.jupiter.api.Test)1 TypeReference (org.web3j.abi.TypeReference)1 Event (org.web3j.abi.datatypes.Event)1 Utf8String (org.web3j.abi.datatypes.Utf8String)1 EthFilter (org.web3j.protocol.core.methods.request.EthFilter)1