Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit be3edb2

Browse files
authored
Merge pull request #539 from boschresearch/feature/411-manage-proof-templates
Add proof templates for proof request creation
2 parents 5f74793 + e2e8efb commit be3edb2

File tree

67 files changed

+4864
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4864
-151
lines changed

backend/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ https://docs.micronaut.io/latest/guide/index.html#ideSetup
3232

3333
1. CLI: Build the UI
3434

35-
```s
35+
```
3636
mvn clean package -Pbuild-frontend
3737
```
3838

@@ -41,7 +41,9 @@ mvn clean package -Pbuild-frontend
4141
Depending on the docker version the .env file either needs to reside in the root directory (older versions) or in the script's directory (newer versions)
4242

4343
[See .env file set up](https://github.com/hyperledger-labs/business-partner-agent/blob/master/scripts/README.md)
44-
44+
```
45+
scripts/.env-example -> scripts/.env
46+
```
4547
3. Start dependent services
4648
```s
4749
# e.g. run from the scripts directory
@@ -73,4 +75,13 @@ If you want to run in web only mode you also have to set:
7375
5. Access the UI
7476

7577
Swagger UI: http://localhost:8080/swagger-ui
76-
Frontend: http://localhost:8080
78+
Frontend: http://localhost:8080
79+
80+
##FAQ
81+
I get a "Micronaut - Error starting Micronaut server: Switching from web only mode to aries is not supported" error?
82+
The schema for web and aries mode differ and the database has to be reset.
83+
`
84+
docker-compose -f scripts/docker-compose.yml down &&
85+
docker volume rm scripts_bpa-wallet-db1 &&
86+
docker-compose -f scripts/docker-compose.yml up bpa-agent1 bpa-wallet-db1
87+
`
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.hyperledger.bpa.api.exception;
20+
21+
public class ProofTemplateException extends RuntimeException {
22+
public ProofTemplateException() {
23+
}
24+
25+
public ProofTemplateException(String message) {
26+
super(message);
27+
}
28+
29+
public ProofTemplateException(String message, Throwable cause) {
30+
super(message, cause);
31+
}
32+
33+
public ProofTemplateException(Throwable cause) {
34+
super(cause);
35+
}
36+
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/ActivityLogConfig.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public class ActivityLogConfig {
4444
ConnectionState.PING_RESPONSE,
4545
ConnectionState.PING_NO_RESPONSE);
4646

47-
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List.of(PresentationExchangeState.REQUEST_RECEIVED);
47+
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List
48+
.of(PresentationExchangeState.REQUEST_RECEIVED);
4849

49-
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(PresentationExchangeState.VERIFIED,
50+
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(
51+
PresentationExchangeState.VERIFIED,
5052
PresentationExchangeState.PRESENTATION_ACKED);
5153

5254
private List<ConnectionState> connectionStatesForActivities;
@@ -63,7 +65,8 @@ public class ActivityLogConfig {
6365
this.acaPyConfig = acaPyConfig;
6466
// 1. set the tasks lists first as they depend on aca py configuration
6567
connectionStatesForTasks = this.isConnectionRequestTask() ? CONNECTION_STATES_TASKS : List.of();
66-
presentationExchangeStatesForTasks = this.isPresentationExchangeTask() ? PRESENTATION_EXCHANGE_STATES_TASKS : List.of();
68+
presentationExchangeStatesForTasks = this.isPresentationExchangeTask() ? PRESENTATION_EXCHANGE_STATES_TASKS
69+
: List.of();
6770

6871
// 2. set the completed state lists
6972
connectionStatesForCompleted = CONNECTION_STATES_COMPLETED;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.hyperledger.bpa.config;
19+
20+
import io.micronaut.context.annotation.Factory;
21+
22+
import javax.inject.Singleton;
23+
import java.time.Clock;
24+
25+
@Factory
26+
public class ClockFactory {
27+
28+
@Singleton
29+
Clock systemClock() {
30+
return Clock.systemUTC();
31+
}
32+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.hyperledger.bpa.config;
19+
20+
import com.fasterxml.jackson.core.JsonProcessingException;
21+
import com.fasterxml.jackson.core.type.TypeReference;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import io.micronaut.context.annotation.Factory;
24+
import io.micronaut.core.convert.TypeConverter;
25+
import lombok.extern.slf4j.Slf4j;
26+
import org.hyperledger.bpa.model.prooftemplate.BPAAttributeGroup;
27+
import org.hyperledger.bpa.model.prooftemplate.BPAAttributeGroups;
28+
29+
import javax.inject.Inject;
30+
import javax.inject.Singleton;
31+
import java.util.List;
32+
import java.util.Optional;
33+
34+
@Slf4j
35+
@Factory
36+
public class TypeConverters {
37+
38+
public static final TypeReference<List<BPAAttributeGroup>> ATTR_REF = new TypeReference<>() {
39+
};
40+
41+
@Inject
42+
ObjectMapper mapper;
43+
44+
@Singleton
45+
TypeConverter<BPAAttributeGroups, String> attrsToString() {
46+
return (object, targetType, context) -> Optional.ofNullable(attributeToString(object));
47+
}
48+
49+
@Singleton
50+
TypeConverter<String, BPAAttributeGroups> stringToAttrs() {
51+
return (object, targetType, context) -> Optional.ofNullable(stringToAttribute(object));
52+
}
53+
54+
private String attributeToString(BPAAttributeGroups f) {
55+
String res = null;
56+
try {
57+
res = mapper.writeValueAsString(f);
58+
} catch (JsonProcessingException e) {
59+
log.error("could not convert to json: ", e);
60+
}
61+
return res;
62+
}
63+
64+
private BPAAttributeGroups stringToAttribute(String f) {
65+
BPAAttributeGroups res = null;
66+
try {
67+
res = mapper.readValue(f, BPAAttributeGroups.class);
68+
} catch (JsonProcessingException e) {
69+
log.error("could not convert from json: {}", f, e);
70+
}
71+
return res;
72+
}
73+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.hyperledger.bpa.controller;
20+
21+
import io.micronaut.http.HttpResponse;
22+
import io.micronaut.http.annotation.*;
23+
import io.micronaut.scheduling.TaskExecutors;
24+
import io.micronaut.scheduling.annotation.ExecuteOn;
25+
import io.micronaut.security.annotation.Secured;
26+
import io.micronaut.security.rules.SecurityRule;
27+
import io.micronaut.validation.Validated;
28+
import io.swagger.v3.oas.annotations.tags.Tag;
29+
import org.hyperledger.bpa.controller.api.prooftemplates.ProofTemplate;
30+
import org.hyperledger.bpa.impl.ProofTemplateManager;
31+
import org.hyperledger.bpa.impl.verification.ValidUUID;
32+
import org.hyperledger.bpa.model.BPAProofTemplate;
33+
34+
import javax.inject.Inject;
35+
import javax.validation.Valid;
36+
import javax.validation.constraints.NotNull;
37+
import java.util.*;
38+
import java.util.stream.Collectors;
39+
40+
@Controller("/api/proof-templates")
41+
@Tag(name = "Proof Template Management")
42+
@Validated
43+
@Secured(SecurityRule.IS_AUTHENTICATED)
44+
@ExecuteOn(TaskExecutors.IO)
45+
public class ProofTemplateController {
46+
47+
@Inject
48+
private ProofTemplateManager proofTemplateManager;
49+
50+
@Get
51+
public HttpResponse<List<ProofTemplate>> listProofTemplates() {
52+
return HttpResponse.ok(
53+
proofTemplateManager.listProofTemplates()
54+
.map(BPAProofTemplate::toRepresentation)
55+
.collect(Collectors.toList()));
56+
}
57+
58+
@Post
59+
public HttpResponse<ProofTemplate> addProofTemplate(@Valid @Body ProofTemplate template) {
60+
if (template.getId() == null) {
61+
BPAProofTemplate persistedTemplate = proofTemplateManager
62+
.addProofTemplate(BPAProofTemplate.fromRepresentation(template));
63+
return HttpResponse.created(persistedTemplate.toRepresentation());
64+
} else {
65+
return HttpResponse.badRequest(template);
66+
}
67+
}
68+
69+
// TODO add possibility to update a template, because we might refer to
70+
// templates via FK, updates have to create new entities.
71+
72+
@Get("/known-condition-operators")
73+
public HttpResponse<Set<String>> listKnownConditionOperators() {
74+
return HttpResponse.ok(proofTemplateManager.getKnownConditionOperators());
75+
}
76+
77+
@Put("/{id}/proof-request/{partnerId}")
78+
public HttpResponse<Void> invokeProofRequestByTemplate(
79+
@PathVariable @ValidUUID @NotNull String id,
80+
@PathVariable @ValidUUID @NotNull String partnerId) {
81+
proofTemplateManager.invokeProofRequestByTemplate(UUID.fromString(id), UUID.fromString(partnerId));
82+
return HttpResponse.ok();
83+
}
84+
85+
@Delete("/{id}")
86+
public HttpResponse<Void> removeProofTemplate(@PathVariable @ValidUUID @NotNull String id) {
87+
proofTemplateManager.removeProofTemplate(UUID.fromString(id));
88+
return HttpResponse.ok();
89+
}
90+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.hyperledger.bpa.controller.api.prooftemplates;
20+
21+
import io.micronaut.core.annotation.Introspected;
22+
import lombok.*;
23+
24+
import javax.validation.Valid;
25+
import javax.validation.constraints.NotEmpty;
26+
import javax.validation.constraints.NotNull;
27+
import java.util.List;
28+
29+
@Data
30+
@AllArgsConstructor
31+
@NoArgsConstructor
32+
@Builder
33+
@Introspected
34+
public class Attribute {
35+
@NotNull
36+
@NotEmpty
37+
String name;
38+
@Valid
39+
@Singular
40+
@NotNull
41+
List<ValueCondition> conditions;
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2020-2021 - for information on the respective copyright owner
3+
* see the NOTICE file and/or the repository at
4+
* https://github.com/hyperledger-labs/business-partner-agent
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.hyperledger.bpa.controller.api.prooftemplates;
20+
21+
import io.micronaut.core.annotation.Introspected;
22+
import lombok.*;
23+
import org.hyperledger.bpa.impl.verification.ValidUUID;
24+
25+
import javax.validation.Valid;
26+
import javax.validation.constraints.NotNull;
27+
import java.util.List;
28+
29+
@Data
30+
@AllArgsConstructor
31+
@NoArgsConstructor
32+
@Builder
33+
@Introspected
34+
public class AttributeGroup {
35+
@NotNull
36+
@ValidUUID
37+
String schemaId;
38+
39+
@Singular
40+
@Valid
41+
@NotNull
42+
List<Attribute> attributes;
43+
44+
@NotNull
45+
@Builder.Default
46+
Boolean nonRevoked = Boolean.FALSE;
47+
@NotNull
48+
@Builder.Default
49+
@Valid
50+
SchemaRestrictions schemaLevelRestrictions = SchemaRestrictions.builder().build();
51+
}

0 commit comments

Comments
 (0)