This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #539 from boschresearch/feature/411-manage-proof-t…
…emplates Add proof templates for proof request creation
- Loading branch information
Showing
67 changed files
with
4,864 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...partner-agent/src/main/java/org/hyperledger/bpa/api/exception/ProofTemplateException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/ClockFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/TypeConverters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...s-partner-agent/src/main/java/org/hyperledger/bpa/controller/ProofTemplateController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...tner-agent/src/main/java/org/hyperledger/bpa/controller/api/prooftemplates/Attribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
51 changes: 51 additions & 0 deletions
51
...agent/src/main/java/org/hyperledger/bpa/controller/api/prooftemplates/AttributeGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.