Skip to content

Commit

Permalink
feat: Framwork VC API, Dismantler VC API, Testcase modificatoin, VC c…
Browse files Browse the repository at this point in the history
…ontext URL in config, VC expiry in config
  • Loading branch information
nitin-vavdiya committed May 30, 2023
1 parent 1666bcc commit 47a6656
Show file tree
Hide file tree
Showing 23 changed files with 1,160 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
package org.eclipse.tractusx.managedidentitywallets.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
* 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 authorityWalletName,
List<String> vcContexts, @DateTimeFormat(pattern = "dd-MM-yyyy") Date vcExpiryDate) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher(RestURI.WALLETS, POST.name())).hasRole(ApplicationConstant.ROLE_ADD_WALLETS) //Create wallet
.requestMatchers(new AntPathRequestMatcher(RestURI.WALLETS, GET.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLETS) //Get all wallet
.requestMatchers(new AntPathRequestMatcher(RestURI.API_WALLETS_IDENTIFIER, GET.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //get wallet by BPN
.requestMatchers(new AntPathRequestMatcher(RestURI.API_WALLETS_IDENTIFIER_CREDENTIALS, POST.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //Store credential
.requestMatchers(new AntPathRequestMatcher(RestURI.API_WALLETS_IDENTIFIER_CREDENTIALS, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET) //Store credential
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, GET.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //get credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_ISSUER_MEMBERSHIP, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //issue Membership Credential
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_ISSUER_MEMBERSHIP, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET) //issue Membership Credential
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_ISSUER_DISMANTLER, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET) //issue dismantler Credential
.requestMatchers(new AntPathRequestMatcher(RestURI.API_CREDENTIALS_ISSUER_FRAMEWORK, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET) //issue dismantler Credential

.requestMatchers(new AntPathRequestMatcher("/error")).permitAll()
.and().oauth2ResourceServer()
.jwt()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* *******************************************************************************
* 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.constant;

import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType;

/**
* The type Miw verifiable credential type.
*/
public class MIWVerifiableCredentialType extends VerifiableCredentialType {

/**
* The constant DISMANTLER_CREDENTIAL_CX.
*/
public static final String DISMANTLER_CREDENTIAL_CX = "DismantlerCredentialCX";

/**
* The constant USE_CASE_FRAMEWORK_CONDITION_CX.
*/
public static final String USE_CASE_FRAMEWORK_CONDITION_CX = "UseCaseFrameworkConditionCX";
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ private RestURI() {
*/
public static final String CREDENTIALS_ISSUER_MEMBERSHIP = "/api/credentials/issuer/membership";

/**
* The constant CREDENTIALS_ISSUER_DISMANTLER.
*/
public static final String CREDENTIALS_ISSUER_DISMANTLER = "/api/credentials/issuer/dismantler";

/**
* The constant API_CREDENTIALS_ISSUER_FRAMEWORK.
*/
public static final String API_CREDENTIALS_ISSUER_FRAMEWORK = "/api/credentials/issuer/framework";

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;
Expand Down Expand Up @@ -73,4 +75,28 @@ public ResponseEntity<List<Credential>> getCredentials(@RequestParam(required =
public ResponseEntity<VerifiableCredential> issueMembershipCredential(@Valid @RequestBody IssueMembershipCredentialRequest issueMembershipCredentialRequest) {
return ResponseEntity.status(HttpStatus.CREATED).body(service.issueMembershipCredential(issueMembershipCredentialRequest));
}

/**
* Issue dismantler credential response entity.
*
* @param request the request
* @return the response entity
*/
@Operation(summary = "Issue a Dismantler Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** OR **update_wallet** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet")
@PostMapping(path = RestURI.CREDENTIALS_ISSUER_DISMANTLER, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<VerifiableCredential> issueDismantlerCredential(@Valid @RequestBody IssueDismantlerCredentialRequest request) {
return ResponseEntity.status(HttpStatus.CREATED).body(service.issueDismantlerCredential(request));
}

/**
* Issue framework credential response entity.
*
* @param request the request
* @return the response entity
*/
@Operation(summary = "Issue a Use Case Verifiable Credential with base wallet issuer", description = "Permission: **update_wallets** OR **update_wallet** (The BPN of base wallet must equal BPN of caller)\n\n Issue a verifiable credential by base wallet")
@PostMapping(path = RestURI.API_CREDENTIALS_ISSUER_FRAMEWORK, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<VerifiableCredential> issueFrameworkCredential(@Valid @RequestBody IssueFrameworkCredentialRequest request) {
return ResponseEntity.status(HttpStatus.CREATED).body(service.issueFrameworkCredential(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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 jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -68,6 +70,41 @@ public ResponseEntity<Wallet> createWallet(@Valid @RequestBody CreateWalletReque
*/
@Operation(summary = "Store Verifiable Credential", description = "Permission: **update_wallets** OR **update_wallet** (The BPN of wallet to extract credentials from must equal BPN of caller) \n\n Store a verifiable credential in the wallet of the given identifier")
@PostMapping(path = RestURI.API_WALLETS_IDENTIFIER_CREDENTIALS, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)

@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(examples = @ExampleObject("""
{
"id": "http://example.edu/credentials/3732",
"@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"
},
"credentialStatus": {
"id": "http://example.edu/api/credentials/status/test#3",
"type": "StatusList2021Entry",
"statusPurpose": "revocation",
"statusListIndex": "3",
"statusListCredential": "http://example.edu/api/credentials/status/test"
},
"proof": {
"type": "Ed25519Signature2018",
"created": "2021-11-17T22:20:27Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:example:76e12ec712ebc6f1c221ebfeb1f#key-1",
"jws": "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..JNerzfrK46Mq4XxYZEnY9xOK80xsEaWCLAHuZsFie1-NTJD17wWWENn_DAlA_OwxGF5dhxUJ05P6Dm8lcmF5Cg"
}
}
"""))
})
public ResponseEntity<Map<String, String>> storeCredential(@RequestBody Map<String, Object> data, @PathVariable(name = "identifier") String identifier) {
return ResponseEntity.status(HttpStatus.CREATED).body(service.storeCredential(data, identifier));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
@Getter
@Setter
@NoArgsConstructor
@Builder
@AllArgsConstructor
@Builder
public class CreateWalletRequest {

@NotBlank
@Size(min = 5, max = 255)
@NotBlank(message = "Please provide BPN")
@Size(min = 5, max = 255, message = "Please provide valid BPN")
private String bpn;

@NotBlank
@Size(min = 5, max = 255)
@NotBlank(message = "Please provide name")
@Size(min = 1, max = 255, message = "Please provide valid name")
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* *******************************************************************************
* 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.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.*;

import java.util.Set;

/**
* The type Issue dismantler credential request.
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class IssueDismantlerCredentialRequest {

@NotBlank(message = "Please provide BPN")
@Size(min = 5, max = 255, message = "Please provide valid BPN")
private String bpn;

@NotBlank(message = "Please provide activity type")
@Size(min = 1, message = "Please provide valid activity type")
private String activityType;

@NotEmpty(message = "Please provide allowed vehicle brands")
private Set<String> allowedVehicleBrands;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* *******************************************************************************
* 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.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.*;


/**
* The type Issue framework credential request.
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class IssueFrameworkCredentialRequest {

@NotBlank(message = "Please provide BPN")
@Size(min = 5, max = 255, message = "Please provide valid BPN")
private String bpn;

@NotBlank(message = "Please provide value")
@Pattern(regexp = "Behavior Twin|PCF|Quality|Resiliency|Sustainability|ID_3.0_Trace", message = "Invalid value, possible values are Behavior Twin, PCF, Quality, Resiliency, Sustainability, ID_3.0_Trace")
private String value;

@NotBlank(message = "Please provide type")
@Pattern(regexp = "cx-behavior-twin|cx-pcf|cx-quality|cx-resiliency|cx-sustainability|cx-traceability", message = "Invalid type, possible values are cx-behavior-twin, cx-pcf, cx-quality, cx-resiliency, cx-sustainability, cx-traceability")
private String type;

@NotBlank(message = "Please provide contract-template")
@JsonProperty("contract-template")
private String contractTemplate;

@NotBlank(message = "Please provide contract-template")
@JsonProperty("contract-version")
private String contractVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
@AllArgsConstructor
public class IssueMembershipCredentialRequest {

@NotBlank
@Size(min = 5, max = 255)
@NotBlank(message = "Please provide BPN")
@Size(min = 5, max = 255, message = "Please provide valid BPN")
private String bpn;
}

Loading

0 comments on commit 47a6656

Please sign in to comment.