You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/03 04:18:22 UTC
[camel] branch main updated: CAMEL-18337: [camel-hyperledger-aries] Add support for /issue-credential/send-proposal (#8099)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new ddc33dee99f CAMEL-18337: [camel-hyperledger-aries] Add support for /issue-credential/send-proposal (#8099)
ddc33dee99f is described below
commit ddc33dee99fd2ab5df18a0a852074ab9ea747000
Author: Thomas Diesler <td...@redhat.com>
AuthorDate: Wed Aug 3 06:18:17 2022 +0200
CAMEL-18337: [camel-hyperledger-aries] Add support for /issue-credential/send-proposal (#8099)
---
.../aries/handler/CredentialsServiceHandler.java | 4 +-
.../handler/IssueCredentialV1ServiceHandler.java | 21 ++++++--
.../aries/handler/PresentProofServiceHandler.java | 27 ++++++++--
.../component/aries/PresentationExchangeTest.java | 57 ++++++++++++++++++++++
4 files changed, 98 insertions(+), 11 deletions(-)
diff --git a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/CredentialsServiceHandler.java b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/CredentialsServiceHandler.java
index cf33f1a8afa..92423fe856a 100644
--- a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/CredentialsServiceHandler.java
+++ b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/CredentialsServiceHandler.java
@@ -23,6 +23,8 @@ import org.apache.camel.component.aries.HyperledgerAriesEndpoint;
import org.apache.camel.component.aries.UnsupportedServiceException;
import org.hyperledger.aries.api.credentials.Credential;
+import static java.util.Collections.emptyList;
+
public class CredentialsServiceHandler extends AbstractServiceHandler {
public CredentialsServiceHandler(HyperledgerAriesEndpoint endpoint) {
@@ -33,7 +35,7 @@ public class CredentialsServiceHandler extends AbstractServiceHandler {
public void process(Exchange exchange, String service) throws Exception {
if (service.equals("/credentials")) {
- List<Credential> credentials = adminClient().credentials().get();
+ List<Credential> credentials = adminClient().credentials().orElse(emptyList());
exchange.getIn().setBody(credentials);
} else {
diff --git a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/IssueCredentialV1ServiceHandler.java b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/IssueCredentialV1ServiceHandler.java
index 56cbbfac88e..7fa09c1b950 100644
--- a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/IssueCredentialV1ServiceHandler.java
+++ b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/IssueCredentialV1ServiceHandler.java
@@ -27,6 +27,7 @@ import org.hyperledger.aries.api.issue_credential_v1.V1CredentialExchange;
import org.hyperledger.aries.api.issue_credential_v1.V1CredentialFreeOfferRequest;
import org.hyperledger.aries.api.issue_credential_v1.V1CredentialIssueRequest;
import org.hyperledger.aries.api.issue_credential_v1.V1CredentialOfferRequest;
+import org.hyperledger.aries.api.issue_credential_v1.V1CredentialProposalRequest;
import org.hyperledger.aries.api.issue_credential_v1.V1CredentialStoreRequest;
public class IssueCredentialV1ServiceHandler extends AbstractServiceHandler {
@@ -48,6 +49,11 @@ public class IssueCredentialV1ServiceHandler extends AbstractServiceHandler {
V1CredentialExchange resObj = createClient().issueCredentialSendOffer(reqObj).get();
exchange.getIn().setBody(resObj);
+ } else if (service.equals("/issue-credential/send-proposal")) {
+ V1CredentialProposalRequest reqObj = assertBody(exchange, V1CredentialProposalRequest.class);
+ V1CredentialExchange resObj = createClient().issueCredentialSendProposal(reqObj).get();
+ exchange.getIn().setBody(resObj);
+
} else if (service.equals("/issue-credential/records")) {
IssueCredentialRecordsFilter reqObj = assertBody(exchange, IssueCredentialRecordsFilter.class);
List<V1CredentialExchange> resObj = createClient().issueCredentialRecords(reqObj).get();
@@ -55,21 +61,26 @@ public class IssueCredentialV1ServiceHandler extends AbstractServiceHandler {
} else if (service.startsWith("/issue-credential/records/")) {
- String credentialExchangeId = getServicePathToken(service, 2);
- AssertState.notNull(credentialExchangeId, "Null credentialExchangeId");
+ String credExchangeId = getServicePathToken(service, 2);
+ AssertState.notNull(credExchangeId, "Null cred_ex_id");
if (service.endsWith("/send-request")) {
- V1CredentialExchange resObj = createClient().issueCredentialRecordsSendRequest(credentialExchangeId).get();
+ V1CredentialExchange resObj = createClient().issueCredentialRecordsSendRequest(credExchangeId).get();
exchange.getIn().setBody(resObj);
} else if (service.endsWith("/issue")) {
V1CredentialIssueRequest reqObj = maybeHeader(exchange, V1CredentialIssueRequest.class);
- V1CredentialExchange resObj = createClient().issueCredentialRecordsIssue(credentialExchangeId, reqObj).get();
+ V1CredentialExchange resObj = createClient().issueCredentialRecordsIssue(credExchangeId, reqObj).get();
exchange.getIn().setBody(resObj);
} else if (service.endsWith("/store")) {
V1CredentialStoreRequest reqObj = maybeBody(exchange, V1CredentialStoreRequest.class);
- V1CredentialExchange resObj = createClient().issueCredentialRecordsStore(credentialExchangeId, reqObj).get();
+ V1CredentialExchange resObj = createClient().issueCredentialRecordsStore(credExchangeId, reqObj).get();
+ exchange.getIn().setBody(resObj);
+
+ } else if (service.endsWith(credExchangeId)) {
+ // /issue-credential/records/{cred_ex_id}
+ V1CredentialExchange resObj = createClient().issueCredentialRecordsGetById(credExchangeId).orElse(null);
exchange.getIn().setBody(resObj);
} else {
diff --git a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/PresentProofServiceHandler.java b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/PresentProofServiceHandler.java
index 1a4a3115f16..59878def556 100644
--- a/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/PresentProofServiceHandler.java
+++ b/components/camel-hyperledger-aries/src/main/java/org/apache/camel/component/aries/handler/PresentProofServiceHandler.java
@@ -16,7 +16,9 @@
*/
package org.apache.camel.component.aries.handler;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.camel.Exchange;
import org.apache.camel.component.aries.HyperledgerAriesEndpoint;
@@ -27,6 +29,8 @@ import org.hyperledger.aries.api.present_proof.PresentationRequest;
import org.hyperledger.aries.api.present_proof.PresentationRequestCredentials;
import org.hyperledger.aries.api.present_proof.PresentationRequestCredentialsFilter;
+import static java.util.Collections.emptyList;
+
public class PresentProofServiceHandler extends AbstractServiceHandler {
public PresentProofServiceHandler(HyperledgerAriesEndpoint endpoint) {
@@ -41,29 +45,42 @@ public class PresentProofServiceHandler extends AbstractServiceHandler {
PresentationExchangeRecord resObj = createClient().presentProofSendRequest(reqObj).get();
exchange.getIn().setBody(resObj);
+ } else if (service.equals("/present-proof/records")) {
+ List<PresentationExchangeRecord> resObj = createClient().presentProofRecords().orElse(emptyList()).stream()
+ .sorted(Collections.reverseOrder((a, b) -> a.getState().ordinal() - b.getState().ordinal()))
+ .peek(pe -> log.info("{}", pe))
+ .collect(Collectors.toList());
+ exchange.getIn().setBody(resObj);
+
} else if (service.startsWith("/present-proof/records/")) {
- String presentationExchangeId = getServicePathToken(service, 2);
+ String presExchangeId = getServicePathToken(service, 2);
if (service.endsWith("/credentials")) {
PresentationRequestCredentialsFilter reqObj = assertBody(exchange, PresentationRequestCredentialsFilter.class);
List<PresentationRequestCredentials> resObj
- = createClient().presentProofRecordsCredentials(presentationExchangeId, reqObj).get();
+ = createClient().presentProofRecordsCredentials(presExchangeId, reqObj)
+ .orElse(emptyList());
exchange.getIn().setBody(resObj);
} else if (service.endsWith("/send-presentation")) {
PresentationRequest reqObj = assertBody(exchange, PresentationRequest.class);
PresentationExchangeRecord resObj
- = createClient().presentProofRecordsSendPresentation(presentationExchangeId, reqObj).get();
+ = createClient().presentProofRecordsSendPresentation(presExchangeId, reqObj).get();
exchange.getIn().setBody(resObj);
} else if (service.endsWith("/verify-presentation")) {
- PresentationExchangeRecord resObj
- = createClient().presentProofRecordsVerifyPresentation(presentationExchangeId).get();
+ PresentationExchangeRecord resObj = createClient().presentProofRecordsVerifyPresentation(presExchangeId).get();
+ exchange.getIn().setBody(resObj);
+
+ } else if (service.endsWith(presExchangeId)) {
+ // /present-proof/records/{pres_ex_id}
+ PresentationExchangeRecord resObj = createClient().presentProofRecordsGetById(presExchangeId).orElse(null);
exchange.getIn().setBody(resObj);
} else {
throw new UnsupportedServiceException(service);
}
+
} else {
throw new UnsupportedServiceException(service);
}
diff --git a/components/camel-hyperledger-aries/src/test/java/org/apache/camel/component/aries/PresentationExchangeTest.java b/components/camel-hyperledger-aries/src/test/java/org/apache/camel/component/aries/PresentationExchangeTest.java
new file mode 100644
index 00000000000..94d9e1975b5
--- /dev/null
+++ b/components/camel-hyperledger-aries/src/test/java/org/apache/camel/component/aries/PresentationExchangeTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aries;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.hyperledger.aries.api.present_proof.PresentationExchangeState;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.PRESENTATIONS_SENT;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.PRESENTATION_ACKED;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.PRESENTATION_RECEIVED;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.PROPOSAL_RECEIVED;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.PROPOSAL_SENT;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.REQUEST_RECEIVED;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.REQUEST_SENT;
+import static org.hyperledger.aries.api.present_proof.PresentationExchangeState.VERIFIED;
+
+public class PresentationExchangeTest extends AbstractCamelAriesTest {
+
+ @Test
+ public void testWorkflow() throws Exception {
+
+ List<PresentationExchangeState> states = Arrays.asList(PROPOSAL_SENT,
+ PROPOSAL_RECEIVED,
+ REQUEST_SENT,
+ REQUEST_RECEIVED,
+ PRESENTATIONS_SENT,
+ PRESENTATION_RECEIVED,
+ VERIFIED,
+ PRESENTATION_ACKED);
+
+ PresentationExchangeState first = states.stream()
+ .peek(ps -> log.info("{}", ps))
+ .sorted(Collections.reverseOrder((a, b) -> a.ordinal() - b.ordinal()))
+ .findFirst().get();
+
+ Assertions.assertEquals(PRESENTATION_ACKED, first);
+ }
+}