Skip to content

Commit

Permalink
feat: Summary VC flow, code changes as per input given in code review…
Browse files Browse the repository at this point in the history
…, test case changes as per summary VC flow
  • Loading branch information
nitin-vavdiya committed Jun 7, 2023
1 parent f33b056 commit 07c4706
Show file tree
Hide file tree
Showing 29 changed files with 513 additions and 241 deletions.
3 changes: 2 additions & 1 deletion README_did_web.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ Currently the minimum is 80%
| AUTH_SERVER_URL | Keycloak server url | |
| SUPPORTED_FRAMEWORK_VC_TYPES | Supported framework VC, provide values ie type1=value1,type2=value2 | cx-behavior-twin=Behavior Twin,cx-pcf=PCF,cx-quality=Quality,cx-resiliency=Resiliency,cx-sustainability=Sustainability,cx-traceability=ID_3.0_Trace |
| ENFORCE_HTTPS_IN_DID_RESOLUTION | Enforce https during web did resolution | true |
| CONTRACT_TEMPLATES_URL | Contract templates URL used in summary VC | https://public.catena-x.org/contracts/ |
| | | |

## Reference
## Reference of external lib

1. https://www.testcontainers.org/modules/databases/postgres/
2. https://github.com/dasniko/testcontainers-keycloak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public record MIWSettings(String host, String encryptionKey, String authorityWal
String authorityWalletName,
List<String> vcContexts, @DateTimeFormat(pattern = "dd-MM-yyyy") Date vcExpiryDate,
String supportedFrameworkVCTypes,
boolean enforceHttps) {
boolean enforceHttps, String contractTemplatesUrl) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.managedidentitywallets.constant.ApplicationConstant;
import org.eclipse.tractusx.managedidentitywallets.constant.ApplicationRole;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -74,31 +74,31 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher(RestURI.DID_DOCUMENTS, GET.name())).permitAll() //Get did document

//wallet APIS
.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 identifier
.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.WALLETS, POST.name())).hasRole(ApplicationRole.ROLE_ADD_WALLETS) //Create wallet
.requestMatchers(new AntPathRequestMatcher(RestURI.WALLETS, GET.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLETS) //Get all wallet
.requestMatchers(new AntPathRequestMatcher(RestURI.API_WALLETS_IDENTIFIER, GET.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLET, ApplicationRole.ROLE_VIEW_WALLETS) //get wallet by identifier
.requestMatchers(new AntPathRequestMatcher(RestURI.API_WALLETS_IDENTIFIER_CREDENTIALS, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLETS, ApplicationRole.ROLE_UPDATE_WALLET) //Store credential

//VP-Generation
.requestMatchers(new AntPathRequestMatcher(RestURI.API_PRESENTATIONS, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLETS, ApplicationConstant.ROLE_UPDATE_WALLET) //Create VP
.requestMatchers(new AntPathRequestMatcher(RestURI.API_PRESENTATIONS, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLETS, ApplicationRole.ROLE_UPDATE_WALLET) //Create VP

//VP - Validation
.requestMatchers(new AntPathRequestMatcher(RestURI.API_PRESENTATIONS_VALIDATION, POST.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLETS, ApplicationConstant.ROLE_VIEW_WALLET) //validate VP
.requestMatchers(new AntPathRequestMatcher(RestURI.API_PRESENTATIONS_VALIDATION, POST.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLETS, ApplicationRole.ROLE_VIEW_WALLET) //validate VP

//VC - Holder
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, GET.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //get credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLET, ApplicationConstant.ROLE_UPDATE_WALLETS) //issue credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, DELETE.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLET) //delete credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, GET.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLET, ApplicationRole.ROLE_VIEW_WALLETS) //get credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLET, ApplicationRole.ROLE_UPDATE_WALLETS) //issue credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS, DELETE.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLET) //delete credentials

//VC - validation
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_VALIDATION, POST.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_VIEW_WALLETS) //validate credentials
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_VALIDATION, POST.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLET, ApplicationRole.ROLE_VIEW_WALLETS) //validate credentials

//VC - Issuer
.requestMatchers(new AntPathRequestMatcher(RestURI.ISSUERS_CREDENTIALS, GET.name())).hasAnyRole(ApplicationConstant.ROLE_VIEW_WALLET, ApplicationConstant.ROLE_UPDATE_WALLETS) //Lis of issuer VC
.requestMatchers(new AntPathRequestMatcher(RestURI.ISSUERS_CREDENTIALS, POST.name())).hasAnyRole(ApplicationConstant.ROLE_UPDATE_WALLET, ApplicationConstant.ROLE_UPDATE_WALLETS) //Issue VC
.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(RestURI.ISSUERS_CREDENTIALS, GET.name())).hasAnyRole(ApplicationRole.ROLE_VIEW_WALLET, ApplicationRole.ROLE_UPDATE_WALLETS) //Lis of issuer VC
.requestMatchers(new AntPathRequestMatcher(RestURI.ISSUERS_CREDENTIALS, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLET, ApplicationRole.ROLE_UPDATE_WALLETS) //Issue VC
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_ISSUER_MEMBERSHIP, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLETS, ApplicationRole.ROLE_UPDATE_WALLET) //issue Membership Credential
.requestMatchers(new AntPathRequestMatcher(RestURI.CREDENTIALS_ISSUER_DISMANTLER, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLETS, ApplicationRole.ROLE_UPDATE_WALLET) //issue dismantler Credential
.requestMatchers(new AntPathRequestMatcher(RestURI.API_CREDENTIALS_ISSUER_FRAMEWORK, POST.name())).hasAnyRole(ApplicationRole.ROLE_UPDATE_WALLETS, ApplicationRole.ROLE_UPDATE_WALLET) //issue dismantler Credential

//error
.requestMatchers(new AntPathRequestMatcher("/error")).permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@

package org.eclipse.tractusx.managedidentitywallets.constant;

/**
* The type Application constant.
*/
public class ApplicationConstant {
public class ApplicationRole {

private ApplicationConstant() {
private ApplicationRole() {
throw new IllegalStateException("Constant class");
}

Expand Down Expand Up @@ -54,16 +51,4 @@ private ApplicationConstant() {
*/
public static final String ROLE_UPDATE_WALLET = "update_wallet";


/**
* The constant DID.
*/
public static final String DID = "did";

/**
* The constant BPN.
*/
public static final String BPN = "bpn";


}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MIWVerifiableCredentialType extends VerifiableCredentialType {

public static final String MEMBERSHIP_CREDENTIAL_CX = "MembershipCredentialCX";
public static final String SUMMARY_CREDENTIAL = "SummaryCredential";
public static final String SUMMARY_LIST_CREDENTIAL = "Summary-List";


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* *******************************************************************************
* 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;

/**
* The type Application constant.
*/
public class StringPool {

public static final String CREDENTIAL_ID = "credentialId";
public static final String VALUE = "value";
public static final String CONTRACT_VERSION = "contract-version";
public static final String ACTIVITY_TYPE = "activityType";
public static final String ALLOWED_VEHICLE_BRANDS = "allowedVehicleBrands";
public static final String VERIFIABLE_CREDENTIALS = "verifiableCredentials";
public static final String VP = "vp";
public static final String VALID = "valid";
public static final String VALIDATE_AUDIENCE = "validateAudience";
public static final String VALIDATE_EXPIRY_DATE = "validateExpiryDate";
public static final String DID_DOCUMENT = "didDocument";
public static final String VEHICLE_DISMANTLE = "vehicleDismantle";

private StringPool() {
throw new IllegalStateException("Constant class");
}

public static final String ISSUER_DID = "issuerDid";
public static final String HOLDER_DID = "holderDid";
public static final String HOLDER_IDENTIFIER = "holderIdentifier";
public static final String NAME = "name";
public static final String CONTRACT_TEMPLATES = "contract-templates";
public static final String CONTRACT_TEMPLATE = "contract-template";
public static final String CX_CREDENTIALS = "CX-Credentials";
public static final String TYPE = "type";
public static final String MEMBER_OF = "memberOf";
public static final String STATUS = "status";
public static final String START_TIME = "startTime";

public static final String ED_25519 = "ED25519";


/**
* The constant DID.
*/
public static final String DID = "did";

/**
* The constant BPN.
*/
public static final String BPN = "bpn";

public static final String BPN_UPPER_CASE = "BPN";

public static final String ID = "id";

public static final String ITEMS = "items";


public static final String CLIENT_ID = "miw_private_client";

public static final String CLIENT_SECRET = "miw_private_client_secret";

public static final String REALM = "miw_test";

public static final String USER_PASSWORD = "s3cr3t";

public static final String VALID_USER_NAME = "valid_user";

public static final String INVALID_USER_NAME = "invalid_user";
public static final String CLIENT_CREDENTIALS = "client_credentials";
public static final String OPENID = "openid";
public static final String BEARER_SPACE = "Bearer ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.eclipse.tractusx.managedidentitywallets.controller;

import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException;
import org.eclipse.tractusx.managedidentitywallets.utils.Validate;
import org.springframework.security.oauth2.jwt.Jwt;
Expand All @@ -43,8 +44,8 @@ public String getBPNFromToken(Principal principal) {
Object principal1 = ((JwtAuthenticationToken) principal).getPrincipal();
Jwt jwt = (Jwt) principal1;

Validate.isFalse(jwt.getClaims().containsKey("BPN")).launch(new ForbiddenException("Invalid token, BPN not found"));
Validate.isFalse(jwt.getClaims().containsKey(StringPool.BPN_UPPER_CASE)).launch(new ForbiddenException("Invalid token, BPN not found"));

return jwt.getClaims().get("BPN").toString();
return jwt.getClaims().get(StringPool.BPN_UPPER_CASE).toString();
}
}
Loading

0 comments on commit 07c4706

Please sign in to comment.