Skip to content

Commit

Permalink
feat: presenation API WIP, code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed May 31, 2023
1 parent aa04faa commit 2c1b5d9
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 112 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation "org.springdoc:springdoc-openapi-starter-common:${openApiVersion}"
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${openApiVersion}"
implementation group: 'com.smartsensesolutions', name: 'commons-dao', version: '0.0.2'
implementation 'org.liquibase:liquibase-core'
implementation 'org.eclipse.tractusx.ssi.lib:cx-ssi-lib:0.0.4'
runtimeOnly 'org.postgresql:postgresql'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* The type Managed identity wallets application.
*/
@SpringBootApplication
@ConfigurationPropertiesScan
@EnableTransactionManagement
public class ManagedIdentityWalletsApplication {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* The type Miw settings.
*/
@ConfigurationProperties(prefix = "miw")
public record MIWSettings(String host, String encryptionKey, String authorityWalletBpn, String authorityWalletName,
public record MIWSettings(String host, String encryptionKey, String authorityWalletBpn, String authorityWalletDid,
String authorityWalletName,
List<String> vcContexts, @DateTimeFormat(pattern = "dd-MM-yyyy") Date vcExpiryDate) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ private RestURI() {
*/
public static final String API_CREDENTIALS_ISSUER_FRAMEWORK = "/api/credentials/issuer/framework";

public static final String API_PRESENTATIONS = "/api/presentations";

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Credential;
import org.eclipse.tractusx.managedidentitywallets.dto.IssueDismantlerCredentialRequest;
import org.eclipse.tractusx.managedidentitywallets.dto.IssueFrameworkCredentialRequest;
import org.eclipse.tractusx.managedidentitywallets.dto.IssueMembershipCredentialRequest;
import org.eclipse.tractusx.managedidentitywallets.service.CredentialService;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -61,14 +59,12 @@ public class CredentialController {
*/
@Operation(description = "Permission: **view_wallets** OR **view_wallet** (The BPN of holderIdentifier must equal BPN of caller)\n\n Search verifiable credentials with filter criteria", summary = "Query Verifiable Credentials")
@GetMapping(path = RestURI.CREDENTIALS, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Page<Credential>> getCredentials(@RequestParam(required = false) String holderIdentifier, @RequestParam(required = false) String id,
@RequestParam(required = false) String issuerIdentifier,
@RequestParam(required = false) List<String> type,
@RequestParam(required = false, defaultValue = "0") int pageNumber,
@RequestParam(required = false, defaultValue = Integer.MAX_VALUE + "") int size,
@RequestParam(required = false, defaultValue = "createdAt") String sortColumn,
@RequestParam(required = false, defaultValue = "desc") String sortTpe) {
return ResponseEntity.status(HttpStatus.OK).body(service.getCredentials(holderIdentifier, id, issuerIdentifier, type, pageNumber, size, sortColumn, sortTpe));
public ResponseEntity<List<VerifiableCredential>> getCredentials(@RequestParam(required = false) String holderIdentifier, @RequestParam(required = false) String id,
@RequestParam(required = false) String issuerIdentifier,
@RequestParam(required = false) List<String> type,
@RequestParam(required = false, defaultValue = "createdAt") String sortColumn,
@RequestParam(required = false, defaultValue = "desc") String sortTpe) {
return ResponseEntity.status(HttpStatus.OK).body(service.getCredentials(holderIdentifier, id, issuerIdentifier, type, sortColumn, sortTpe));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.service.PresentationService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequiredArgsConstructor
@Tag(name = "VerifiablePresentations")
public class PresentationController {

private final PresentationService presentationService;

@Operation(summary = "Create Verifiable Presentation", description = "Permission: **update_wallets** OR **update_wallet** (The BPN of the issuer of the Verifiable Presentation must equal to BPN of caller) \n\n Create a verifiable presentation from a list of verifiable credentials, signed by the holder")
@PostMapping(path = RestURI.API_PRESENTATIONS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)

@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(examples = @ExampleObject("""
{
"holderIdentifier": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"verifiableCredentials": [
{
"id": "http://example.edu/credentials/333",
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"type": [
"University-Degree-Credential, VerifiableCredential"
],
"issuer": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"issuanceDate": "2019-06-16T18:56:59Z",
"expirationDate": "2019-06-17T18:56:59Z",
"credentialSubject": {
"college": "Test-University"
},
"proof": {
"type": "Ed25519Signature2018",
"created": "2021-11-17T22:20:27Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:example:76e12ec712ebc6f1c221ebfeb1f#keys-1",
"jws": "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..JNerzfrK46Mq4XxYZEnY9xOK80xsEaWCLAHuZsFie1-NTJD17wWWENn_DAlA_OwxGF5dhxUJ05P6Dm8lcmF5Cg"
}
}
]
}
"""))
})
public ResponseEntity<Map<String, Object>> createPresentation(@RequestBody Map<String, Object> data,
@RequestParam(name = "asJwt", required = false, defaultValue = "false") boolean asJwt
) {
return ResponseEntity.status(HttpStatus.CREATED).body(presentationService.createPresentation(data, asJwt, "smartSense"));
}
}
Loading

0 comments on commit 2c1b5d9

Please sign in to comment.