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

Commit

Permalink
Merge pull request #539 from boschresearch/feature/411-manage-proof-t…
Browse files Browse the repository at this point in the history
…emplates

Add proof templates for proof request creation
  • Loading branch information
l-wegner authored Aug 6, 2021
2 parents 5f74793 + e2e8efb commit be3edb2
Show file tree
Hide file tree
Showing 67 changed files with 4,864 additions and 151 deletions.
17 changes: 14 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ https://docs.micronaut.io/latest/guide/index.html#ideSetup

1. CLI: Build the UI

```s
```
mvn clean package -Pbuild-frontend
```

Expand All @@ -41,7 +41,9 @@ mvn clean package -Pbuild-frontend
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)

[See .env file set up](https://github.com/hyperledger-labs/business-partner-agent/blob/master/scripts/README.md)

```
scripts/.env-example -> scripts/.env
```
3. Start dependent services
```s
# e.g. run from the scripts directory
Expand Down Expand Up @@ -73,4 +75,13 @@ If you want to run in web only mode you also have to set:
5. Access the UI

Swagger UI: http://localhost:8080/swagger-ui
Frontend: http://localhost:8080
Frontend: http://localhost:8080

##FAQ
I get a "Micronaut - Error starting Micronaut server: Switching from web only mode to aries is not supported" error?
The schema for web and aries mode differ and the database has to be reset.
`
docker-compose -f scripts/docker-compose.yml down &&
docker volume rm scripts_bpa-wallet-db1 &&
docker-compose -f scripts/docker-compose.yml up bpa-agent1 bpa-wallet-db1
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.api.exception;

public class ProofTemplateException extends RuntimeException {
public ProofTemplateException() {
}

public ProofTemplateException(String message) {
super(message);
}

public ProofTemplateException(String message, Throwable cause) {
super(message, cause);
}

public ProofTemplateException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public class ActivityLogConfig {
ConnectionState.PING_RESPONSE,
ConnectionState.PING_NO_RESPONSE);

private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List.of(PresentationExchangeState.REQUEST_RECEIVED);
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List
.of(PresentationExchangeState.REQUEST_RECEIVED);

private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(PresentationExchangeState.VERIFIED,
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(
PresentationExchangeState.VERIFIED,
PresentationExchangeState.PRESENTATION_ACKED);

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

// 2. set the completed state lists
connectionStatesForCompleted = CONNECTION_STATES_COMPLETED;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.config;

import io.micronaut.context.annotation.Factory;

import javax.inject.Singleton;
import java.time.Clock;

@Factory
public class ClockFactory {

@Singleton
Clock systemClock() {
return Clock.systemUTC();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.micronaut.context.annotation.Factory;
import io.micronaut.core.convert.TypeConverter;
import lombok.extern.slf4j.Slf4j;
import org.hyperledger.bpa.model.prooftemplate.BPAAttributeGroup;
import org.hyperledger.bpa.model.prooftemplate.BPAAttributeGroups;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Optional;

@Slf4j
@Factory
public class TypeConverters {

public static final TypeReference<List<BPAAttributeGroup>> ATTR_REF = new TypeReference<>() {
};

@Inject
ObjectMapper mapper;

@Singleton
TypeConverter<BPAAttributeGroups, String> attrsToString() {
return (object, targetType, context) -> Optional.ofNullable(attributeToString(object));
}

@Singleton
TypeConverter<String, BPAAttributeGroups> stringToAttrs() {
return (object, targetType, context) -> Optional.ofNullable(stringToAttribute(object));
}

private String attributeToString(BPAAttributeGroups f) {
String res = null;
try {
res = mapper.writeValueAsString(f);
} catch (JsonProcessingException e) {
log.error("could not convert to json: ", e);
}
return res;
}

private BPAAttributeGroups stringToAttribute(String f) {
BPAAttributeGroups res = null;
try {
res = mapper.readValue(f, BPAAttributeGroups.class);
} catch (JsonProcessingException e) {
log.error("could not convert from json: {}", f, e);
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.controller;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.*;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.validation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.hyperledger.bpa.controller.api.prooftemplates.ProofTemplate;
import org.hyperledger.bpa.impl.ProofTemplateManager;
import org.hyperledger.bpa.impl.verification.ValidUUID;
import org.hyperledger.bpa.model.BPAProofTemplate;

import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;

@Controller("/api/proof-templates")
@Tag(name = "Proof Template Management")
@Validated
@Secured(SecurityRule.IS_AUTHENTICATED)
@ExecuteOn(TaskExecutors.IO)
public class ProofTemplateController {

@Inject
private ProofTemplateManager proofTemplateManager;

@Get
public HttpResponse<List<ProofTemplate>> listProofTemplates() {
return HttpResponse.ok(
proofTemplateManager.listProofTemplates()
.map(BPAProofTemplate::toRepresentation)
.collect(Collectors.toList()));
}

@Post
public HttpResponse<ProofTemplate> addProofTemplate(@Valid @Body ProofTemplate template) {
if (template.getId() == null) {
BPAProofTemplate persistedTemplate = proofTemplateManager
.addProofTemplate(BPAProofTemplate.fromRepresentation(template));
return HttpResponse.created(persistedTemplate.toRepresentation());
} else {
return HttpResponse.badRequest(template);
}
}

// TODO add possibility to update a template, because we might refer to
// templates via FK, updates have to create new entities.

@Get("/known-condition-operators")
public HttpResponse<Set<String>> listKnownConditionOperators() {
return HttpResponse.ok(proofTemplateManager.getKnownConditionOperators());
}

@Put("/{id}/proof-request/{partnerId}")
public HttpResponse<Void> invokeProofRequestByTemplate(
@PathVariable @ValidUUID @NotNull String id,
@PathVariable @ValidUUID @NotNull String partnerId) {
proofTemplateManager.invokeProofRequestByTemplate(UUID.fromString(id), UUID.fromString(partnerId));
return HttpResponse.ok();
}

@Delete("/{id}")
public HttpResponse<Void> removeProofTemplate(@PathVariable @ValidUUID @NotNull String id) {
proofTemplateManager.removeProofTemplate(UUID.fromString(id));
return HttpResponse.ok();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.controller.api.prooftemplates;

import io.micronaut.core.annotation.Introspected;
import lombok.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Introspected
public class Attribute {
@NotNull
@NotEmpty
String name;
@Valid
@Singular
@NotNull
List<ValueCondition> conditions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2020-2021 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/business-partner-agent
*
* Licensed 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.hyperledger.bpa.controller.api.prooftemplates;

import io.micronaut.core.annotation.Introspected;
import lombok.*;
import org.hyperledger.bpa.impl.verification.ValidUUID;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Introspected
public class AttributeGroup {
@NotNull
@ValidUUID
String schemaId;

@Singular
@Valid
@NotNull
List<Attribute> attributes;

@NotNull
@Builder.Default
Boolean nonRevoked = Boolean.FALSE;
@NotNull
@Builder.Default
@Valid
SchemaRestrictions schemaLevelRestrictions = SchemaRestrictions.builder().build();
}
Loading

0 comments on commit be3edb2

Please sign in to comment.