From feec803af1c50fbd9ebf834a67139a6b4da6bd3a Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Date: Mon, 23 Sep 2024 15:52:35 +0530 Subject: [PATCH 1/9] [INJICERT-444] update to release URL (#61) Signed-off-by: Harsh Vardhan --- .github/workflows/push-trigger.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index d8aeed6..944c9db 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -44,7 +44,7 @@ jobs: secrets: OSSRH_USER: ${{ secrets.OSSRH_USER }} OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} - OSSRH_URL: ${{ secrets.RELEASE_URL }} + OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SECRET: ${{ secrets.GPG_SECRET }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} @@ -85,7 +85,7 @@ jobs: secrets: OSSRH_USER: ${{ secrets.OSSRH_USER }} OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} - OSSRH_URL: ${{ secrets.RELEASE_URL }} + OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SECRET: ${{ secrets.GPG_SECRET }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} From 9873f51cfea42e1fff15ec6657822d91e90263ce Mon Sep 17 00:00:00 2001 From: techno-467 Date: Wed, 25 Sep 2024 17:50:42 +0530 Subject: [PATCH 2/9] [DSD-6313] updated pom.xml file --- mock-certify-plugin/pom.xml | 6 +++--- mosip-identity-certify-plugin/pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index 828b75f..0d0dc95 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -44,11 +44,11 @@ 3.7.1 21 21 - 3.10.1 - 3.2.5 + 3.8.0 + 2.22.0 1.5 2.2.1 - 6.1.0 + 1.6.14 3.0.1 0.8.11 3.6.3 diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index 633e53d..b1030ab 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -76,10 +76,10 @@ 21 21 21 - 2.4 + 3.8.0 3.2.0 3.3.2 - 3.2.5 + 2.22.0 3.7.1 0.8.11 3.6.3 From 751e6f233164d7132ef98f251d3872e7c193b513 Mon Sep 17 00:00:00 2001 From: Praful Rakhade <99539100+prafulrakhade@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:02:25 +0530 Subject: [PATCH 3/9] [DSD-6313] updated pom.xml file Signed-off-by: techno-467 --- mock-certify-plugin/pom.xml | 2 +- mosip-identity-certify-plugin/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index 0d0dc95..ec495cd 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -44,7 +44,7 @@ 3.7.1 21 21 - 3.8.0 + 3.9.9 2.22.0 1.5 2.2.1 diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index b1030ab..1e7efd5 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -76,7 +76,7 @@ 21 21 21 - 3.8.0 + 3.9.9 3.2.0 3.3.2 2.22.0 From 50394d30fc98541a5aebe97e3e12568465c271f8 Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Date: Fri, 27 Sep 2024 11:45:38 +0530 Subject: [PATCH 4/9] Revert "[DSD-6313] updated pom.xml file" Signed-off-by: Harsh Vardhan --- mock-certify-plugin/pom.xml | 2 +- mosip-identity-certify-plugin/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index ec495cd..0d0dc95 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -44,7 +44,7 @@ 3.7.1 21 21 - 3.9.9 + 3.8.0 2.22.0 1.5 2.2.1 diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index 1e7efd5..b1030ab 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -76,7 +76,7 @@ 21 21 21 - 3.9.9 + 3.8.0 3.2.0 3.3.2 2.22.0 From 2172ef31563ff3c5db3fd2d5771e41e53ee7d3ee Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Date: Tue, 1 Oct 2024 13:10:15 +0530 Subject: [PATCH 5/9] [INJICERT-444] bump up version to 0.9.1-SNAPSHOT Signed-off-by: Harsh Vardhan --- mock-certify-plugin/pom.xml | 2 +- mosip-identity-certify-plugin/pom.xml | 4 ++-- sunbird-rc-certify-integration-impl/pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index 0d0dc95..ca02026 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -66,7 +66,7 @@ io.mosip.certify certify-core - 0.9.0 + 0.9.1-SNAPSHOT provided diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index b1030ab..5c0bfbf 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -98,13 +98,13 @@ io.mosip.certify certify-core - 0.9.0 + 0.9.1-SNAPSHOT provided io.mosip.certify certify-integration-api - 0.9.0 + 0.9.1-SNAPSHOT provided diff --git a/sunbird-rc-certify-integration-impl/pom.xml b/sunbird-rc-certify-integration-impl/pom.xml index b043068..798c5a1 100644 --- a/sunbird-rc-certify-integration-impl/pom.xml +++ b/sunbird-rc-certify-integration-impl/pom.xml @@ -54,7 +54,7 @@ io.mosip.certify certify-integration-api - 0.9.0 + 0.9.1-SNAPSHOT provided From 147138cc2825b67f9c478479bafa988c0d9b68b3 Mon Sep 17 00:00:00 2001 From: Prafulrakhade Date: Wed, 2 Oct 2024 01:14:20 +0000 Subject: [PATCH 6/9] Updated Pom versions for release changes Signed-off-by: GitHub --- .github/workflows/push-trigger.yml | 4 ++-- mock-certify-plugin/pom.xml | 2 +- mosip-identity-certify-plugin/pom.xml | 4 ++-- sunbird-rc-certify-integration-impl/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index 944c9db..d8aeed6 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -44,7 +44,7 @@ jobs: secrets: OSSRH_USER: ${{ secrets.OSSRH_USER }} OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} - OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} + OSSRH_URL: ${{ secrets.RELEASE_URL }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SECRET: ${{ secrets.GPG_SECRET }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} @@ -85,7 +85,7 @@ jobs: secrets: OSSRH_USER: ${{ secrets.OSSRH_USER }} OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} - OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} + OSSRH_URL: ${{ secrets.RELEASE_URL }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SECRET: ${{ secrets.GPG_SECRET }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index ca02026..041d6ba 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -66,7 +66,7 @@ io.mosip.certify certify-core - 0.9.1-SNAPSHOT + 0.9.1 provided diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index 5c0bfbf..b40d8a8 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -98,13 +98,13 @@ io.mosip.certify certify-core - 0.9.1-SNAPSHOT + 0.9.1 provided io.mosip.certify certify-integration-api - 0.9.1-SNAPSHOT + 0.9.1 provided diff --git a/sunbird-rc-certify-integration-impl/pom.xml b/sunbird-rc-certify-integration-impl/pom.xml index 798c5a1..f67b42d 100644 --- a/sunbird-rc-certify-integration-impl/pom.xml +++ b/sunbird-rc-certify-integration-impl/pom.xml @@ -54,7 +54,7 @@ io.mosip.certify certify-integration-api - 0.9.1-SNAPSHOT + 0.9.1 provided From 7e3949172d926e3d95055b4725a87bf6d6d6f153 Mon Sep 17 00:00:00 2001 From: techno-467 Date: Wed, 2 Oct 2024 06:52:22 +0530 Subject: [PATCH 7/9] [DSD-6362] inji-certify 0.9.1 release changes --- mock-certify-plugin/pom.xml | 2 +- mosip-identity-certify-plugin/pom.xml | 2 +- sunbird-rc-certify-integration-impl/pom.xml | 2 +- sunbird-rc-esignet-integration-impl/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mock-certify-plugin/pom.xml b/mock-certify-plugin/pom.xml index 041d6ba..e8639ad 100644 --- a/mock-certify-plugin/pom.xml +++ b/mock-certify-plugin/pom.xml @@ -10,7 +10,7 @@ io.mosip.certify mock-certify-plugin - 0.2.1-SNAPSHOT + 0.2.1 jar mock-certify-integration-impl diff --git a/mosip-identity-certify-plugin/pom.xml b/mosip-identity-certify-plugin/pom.xml index b40d8a8..ae8f34f 100644 --- a/mosip-identity-certify-plugin/pom.xml +++ b/mosip-identity-certify-plugin/pom.xml @@ -8,7 +8,7 @@ 4.0.0 io.mosip.certify mosip-identity-certify-plugin - 0.2.1-SNAPSHOT + 0.2.1 jar mosipid-certify-integration-impl diff --git a/sunbird-rc-certify-integration-impl/pom.xml b/sunbird-rc-certify-integration-impl/pom.xml index f67b42d..c045ea8 100644 --- a/sunbird-rc-certify-integration-impl/pom.xml +++ b/sunbird-rc-certify-integration-impl/pom.xml @@ -8,7 +8,7 @@ 4.0.0 io.mosip.certify.sunbirdrc sunbird-rc-certify-integration-impl - 0.2.1-SNAPSHOT + 0.2.1 jar sunbird-rc-certify-integration-impl diff --git a/sunbird-rc-esignet-integration-impl/pom.xml b/sunbird-rc-esignet-integration-impl/pom.xml index 65b710c..351d0c0 100644 --- a/sunbird-rc-esignet-integration-impl/pom.xml +++ b/sunbird-rc-esignet-integration-impl/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.mosip.esignet.sunbirdrc sunbird-rc-esignet-integration-impl - 0.2.1-SNAPSHOT + 0.2.1 jar sunbird-rc-esignet-integration-impl From 2cb9383a182cf3dbc479282f11b3d64e040b8631 Mon Sep 17 00:00:00 2001 From: Manjunath Bhagwat Date: Tue, 17 Dec 2024 18:07:27 +0530 Subject: [PATCH 8/9] Added the code for fetching the individual id --- sunbird-rc-certify-integration-impl/pom.xml | 42 ++++ .../service/SunbirdRCVCIssuancePlugin.java | 196 +++++++++++++++++- 2 files changed, 234 insertions(+), 4 deletions(-) diff --git a/sunbird-rc-certify-integration-impl/pom.xml b/sunbird-rc-certify-integration-impl/pom.xml index c045ea8..3728988 100644 --- a/sunbird-rc-certify-integration-impl/pom.xml +++ b/sunbird-rc-certify-integration-impl/pom.xml @@ -49,6 +49,7 @@ 3.0.1 0.8.11 3.6.3 + 1.3.0-beta.1 @@ -58,6 +59,29 @@ provided + + io.mosip.esignet + esignet-core + 1.4.1 + + + * + * + + + + + io.mosip.esignet + esignet-integration-api + 1.4.1 + + + * + * + + + + org.projectlombok lombok @@ -65,6 +89,24 @@ 1.18.30 + + io.mosip.kernel + kernel-keymanager-service + ${kernel-keymanager-service.version} + provided + lib + + + org.springframework.cloud + spring-cloud-starter-sleuth + + + org.springframework.security + spring-security-test + + + + org.apache.velocity velocity diff --git a/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java b/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java index 68b51df..67a300b 100644 --- a/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java +++ b/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java @@ -37,6 +37,11 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.cache.CacheManager; +import org.springframework.http.HttpHeaders; + +import io.mosip.esignet.core.dto.OIDCTransaction; + import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; @@ -46,8 +51,21 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - - +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.io.PrintWriter; +import java.util.Base64; +import java.util.Objects; + +import java.time.ZoneOffset; +import java.time.LocalDateTime; + +import javax.crypto.Cipher; +import java.security.Key; +import io.mosip.kernel.core.keymanager.spi.KeyStore; +import io.mosip.kernel.keymanagerservice.constant.KeymanagerConstant; +import io.mosip.kernel.keymanagerservice.entity.KeyAlias; +import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper; @ConditionalOnProperty(value = "mosip.certify.integration.vci-plugin", havingValue = "SunbirdRCVCIssuancePlugin") @Component @@ -74,23 +92,55 @@ public class SunbirdRCVCIssuancePlugin implements VCIssuancePlugin { private final String FILTER_EQUALS_OPERATOR = "eq"; + public static final String AES_CIPHER_FAILED = "aes_cipher_failed"; + + public static final String OIDC_SERVICE_APP_ID = "CERTIFY_SERVICE"; + private final String PSUT_TOKEN="psut"; + public static final String NO_UNIQUE_ALIAS = "no_unique_alias"; + + private Base64.Decoder urlSafeDecoder = Base64.getUrlDecoder(); + @Autowired Environment env; @Autowired ObjectMapper mapper; + @Autowired + private KeyStore keyStore; + @Autowired private RestTemplate restTemplate; + @Autowired + private KeymanagerDBHelper dbHelper; + @Value("${mosip.certify.vciplugin.sunbird-rc.issue-credential-url}") String issueCredentialUrl; + @Value("${io.credissuer.com.get-credential-url}") + String getCredentialUrl; + + @Value("${mosip.certify.cache.secure.individual-id}") + private boolean secureIndividualId; + + @Value("${mosip.certify.cache.store.individual-id}") + private boolean storeIndividualId; + + @Value("${mosip.certify.cache.security.secretkey.reference-id}") + private String cacheSecretKeyRefId; + @Value("${mosip.certify.vciplugin.sunbird-rc.enable-psut-based-registry-search:false}") private boolean enablePSUTBasedRegistrySearch; + @Value("${mosip.esignet.authenticator.credissuer.bearer-token}") + private String credIssuerBeaerToken; + + @Value("${mosip.certify.cache.security.algorithm-name}") + private String aesECBTransformation; + @Value("#{'${mosip.certify.vciplugin.sunbird-rc.supported-credential-types}'.split(',')}") List supportedCredentialTypes; @@ -100,6 +150,12 @@ public class SunbirdRCVCIssuancePlugin implements VCIssuancePlugin { private VelocityEngine vEngine; + @Autowired + CacheManager cacheManager; + @Value("${mosip.esignet.ida.vci-user-info-cache}") + private String userinfoCache; + private static final String ACCESS_TOKEN_HASH = "accessTokenHash"; + @PostConstruct public void initialize() throws VCIExchangeException { @@ -121,11 +177,11 @@ public InputStream getResourceStream(String name) throws ResourceNotFoundExcepti vEngine.init(); //Validate all the supported VC for (String credentialType : supportedCredentialTypes) { - validateAndCachePropertiesForCredentialType(credentialType.trim()); + //validateAndCachePropertiesForCredentialType(credentialType.trim()); } } - @Override + /*@Override public VCResult getVerifiableCredentialWithLinkedDataProof(VCRequestDto vcRequestDto, String holderId, Map identityDetails) throws VCIExchangeException { if (vcRequestDto == null || vcRequestDto.getType() == null) { throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); @@ -171,6 +227,138 @@ public VCResult getVerifiableCredentialWithLinkedDataProof(VCReque vcResult.setFormat(LINKED_DATA_PROOF_VC_FORMAT); return vcResult; } +*/ + + @Override + public VCResult getVerifiableCredentialWithLinkedDataProof(VCRequestDto vcRequestDto, String holderId, + Map identityDetails) throws VCIExchangeException { + JsonLDObject vcJsonLdObject = null; + String individualId = null; + try { + OIDCTransaction transaction = getOAuthTransaction(identityDetails.get(ACCESS_TOKEN_HASH).toString()); + individualId = getIndividualId(transaction.getIndividualId()); + } catch (Exception e) { + throw new RuntimeException(e); + } + try { + VCResult vcResult = new VCResult(); + Map vcResponseMap = fetchCredential(getCredentialUrl + individualId); + vcJsonLdObject = JsonLDObject.fromJsonObject((Map)vcResponseMap.get(CREDENTIAL_OBJECT_KEY)); + vcResult.setCredential(vcJsonLdObject); + vcResult.setFormat("ldp_vc"); + return vcResult; + } catch (Exception e) { + log.error("Failed to build credissuer response", e); + } + throw new VCIExchangeException(); + } + + private Map fetchCredential(String entityUrl) throws VCIExchangeException { + RequestEntity requestEntity = RequestEntity + .get(UriComponentsBuilder.fromUriString(entityUrl).build().toUri()) + .header("Authorization", "Bearer " + credIssuerBeaerToken) // Set the headers + .build(); + ResponseEntity> responseEntity = restTemplate.exchange(requestEntity, + new ParameterizedTypeReference>() {}); + if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) { + return responseEntity.getBody(); + }else { + log.error("Credissuer service is not running. Status Code: " , responseEntity.getStatusCode()); + throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); + } + } + + /* @SuppressWarnings("unchecked") + public String getOAuthTransaction(String accessTokenHash) throws Exception { + try { + if (cacheManager.getCache(userinfoCache) != null) { + return cacheManager.getCache(userinfoCache).get(accessTokenHash, OIDCTransaction.class); //NOSONAR getCache() will not be returning null here. + } + throw new Exception("cache_missing>>>>>>>>"); + } catch (Exception ex) { + // Log or handle the exception as needed + ex.printStackTrace(); + // Extract individual ID from the stack trace + String individualId = extractIndividualIdFromStackTrace(ex); + return individualId; + } + }*/ + + @SuppressWarnings("unchecked") + public OIDCTransaction getOAuthTransaction(String accessTokenHash) throws Exception { + if (cacheManager.getCache(userinfoCache) != null) { + System.out.println("Inside getOAuthTransaction>>>>>>>>"); + try { + OIDCTransaction oIDCTransaction = cacheManager.getCache(userinfoCache).get(accessTokenHash, OIDCTransaction.class); //NOSONAR getCache() will not be returning null here. + log.info("oIDCTransaction>>>>>>>>", oIDCTransaction); + return oIDCTransaction; + } catch (Exception e) { + log.error("Exception occured while fetching the cache", e); + throw new Exception(e); + } + + } + throw new Exception("cache_missing>>>>>"); + } + + protected String getIndividualId(String encryptedIndividualId) throws Exception { + if (!storeIndividualId) + return null; + return secureIndividualId ? decryptIndividualId(encryptedIndividualId) : encryptedIndividualId; + } + + private String decryptIndividualId(String encryptedIndividualId) throws Exception { + try { + Cipher cipher = Cipher.getInstance(aesECBTransformation); + byte[] decodedBytes = b64Decode(encryptedIndividualId); + cipher.init(Cipher.DECRYPT_MODE, getSecretKeyFromHSM()); + return new String(cipher.doFinal(decodedBytes, 0, decodedBytes.length)); + } catch (Exception e) { + log.error("Error Cipher Operations of provided secret data.", e); + throw new Exception(AES_CIPHER_FAILED); + } + } + + private Key getSecretKeyFromHSM() throws Exception { + String keyAlias = getKeyAlias(OIDC_SERVICE_APP_ID, cacheSecretKeyRefId); + if (Objects.nonNull(keyAlias)) { + return keyStore.getSymmetricKey(keyAlias); + } + throw new Exception(NO_UNIQUE_ALIAS); + } + + private String getKeyAlias(String keyAppId, String keyRefId) throws Exception { + Map> keyAliasMap = dbHelper.getKeyAliases(keyAppId, keyRefId, + LocalDateTime.now(ZoneOffset.UTC)); + List currentKeyAliases = keyAliasMap.get(KeymanagerConstant.CURRENTKEYALIAS); + if (!currentKeyAliases.isEmpty() && currentKeyAliases.size() == 1) { + return currentKeyAliases.get(0).getAlias(); + } + log.error("CurrentKeyAlias is not unique. KeyAlias count: {}", currentKeyAliases.size()); + throw new Exception(NO_UNIQUE_ALIAS); + } + + private String extractIndividualIdFromStackTrace(Exception ex) { + String stackTrace = getStackTrace(ex); + // Define a regular expression pattern to match the individualId + Pattern pattern = Pattern.compile("individualId=([a-zA-Z0-9_-]+)"); + Matcher matcher = pattern.matcher(stackTrace); + // Find the first occurrence of the pattern + if (matcher.find()) { + return matcher.group(1); // Group 1 contains the matched individualId + } + return null; // Return null if individualId is not found + } + + private String getStackTrace(Exception ex) { + StringWriter sw = new StringWriter(); + ex.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + + private byte[] b64Decode(String value) { + return urlSafeDecoder.decode(value); + }; @Override public VCResult getVerifiableCredential(VCRequestDto vcRequestDto, String holderId, Map identityDetails) throws VCIExchangeException { From ab44a7fa5edaee277d9c852872acf712f5e405d6 Mon Sep 17 00:00:00 2001 From: Nandeesh Date: Tue, 17 Dec 2024 19:36:48 +0530 Subject: [PATCH 9/9] Refactored the code and added the logs to print the individualID. --- .../service/SunbirdRCVCIssuancePlugin.java | 83 +------------------ 1 file changed, 1 insertion(+), 82 deletions(-) diff --git a/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java b/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java index 67a300b..0bc7a70 100644 --- a/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java +++ b/sunbird-rc-certify-integration-impl/src/main/java/io/mosip/certify/sunbirdrc/integration/service/SunbirdRCVCIssuancePlugin.java @@ -181,54 +181,6 @@ public InputStream getResourceStream(String name) throws ResourceNotFoundExcepti } } - /*@Override - public VCResult getVerifiableCredentialWithLinkedDataProof(VCRequestDto vcRequestDto, String holderId, Map identityDetails) throws VCIExchangeException { - if (vcRequestDto == null || vcRequestDto.getType() == null) { - throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); - } - List types = vcRequestDto.getType(); - if (types.isEmpty() || !types.get(0).equals("VerifiableCredential")) { - log.error("Invalid request: first item in type is not VerifiableCredential"); - throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); - } - types.remove(0); - String requestedCredentialType = String.join("-", types); - //Check if the key is in the supported-credential-types - if (!supportedCredentialTypes.contains(requestedCredentialType)) { - log.error("Credential type is not supported"); - throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); - } - //Validate context of vcrequestdto with template - List contextList=vcRequestDto.getContext(); - for(String supportedType:supportedCredentialTypes){ - Template template= credentialTypeTemplates.get(supportedType); - validateContextUrl(template,contextList); - } - - String registrySearchField = (identityDetails.containsKey("sub")) ? (String) identityDetails.get("sub") : null; - if (registrySearchField == null) { - log.error("Invalid request: registrySearchField is null"); - throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); - } - Map responseRegistryMap; - if(enablePSUTBasedRegistrySearch){ - String registrySearchUrl=credentialTypeConfigMap.get(requestedCredentialType).get(REGISTRY_SEARCH_URL); - responseRegistryMap= fetchRegistryObjectByPSUT(registrySearchUrl,registrySearchField); - }else { - String registryUrl=credentialTypeConfigMap.get(requestedCredentialType).get(REGISTRY_GET_URL); - responseRegistryMap =fetchRegistryObject(registryUrl+ registrySearchField); - } - Map credentialRequestMap = createCredentialIssueRequest(requestedCredentialType, responseRegistryMap,vcRequestDto,holderId); - Map vcResponseMap =sendCredentialIssueRequest(credentialRequestMap); - - VCResult vcResult = new VCResult(); - JsonLDObject vcJsonLdObject = JsonLDObject.fromJsonObject((Map)vcResponseMap.get(CREDENTIAL_OBJECT_KEY)); - vcResult.setCredential(vcJsonLdObject); - vcResult.setFormat(LINKED_DATA_PROOF_VC_FORMAT); - return vcResult; - } -*/ - @Override public VCResult getVerifiableCredentialWithLinkedDataProof(VCRequestDto vcRequestDto, String holderId, Map identityDetails) throws VCIExchangeException { @@ -237,6 +189,7 @@ public VCResult getVerifiableCredentialWithLinkedDataProof(VCReque try { OIDCTransaction transaction = getOAuthTransaction(identityDetails.get(ACCESS_TOKEN_HASH).toString()); individualId = getIndividualId(transaction.getIndividualId()); + System.out.println("individualId : "+individualId); } catch (Exception e) { throw new RuntimeException(e); } @@ -268,29 +221,11 @@ private Map fetchCredential(String entityUrl) throws VCIExchangeE } } - /* @SuppressWarnings("unchecked") - public String getOAuthTransaction(String accessTokenHash) throws Exception { - try { - if (cacheManager.getCache(userinfoCache) != null) { - return cacheManager.getCache(userinfoCache).get(accessTokenHash, OIDCTransaction.class); //NOSONAR getCache() will not be returning null here. - } - throw new Exception("cache_missing>>>>>>>>"); - } catch (Exception ex) { - // Log or handle the exception as needed - ex.printStackTrace(); - // Extract individual ID from the stack trace - String individualId = extractIndividualIdFromStackTrace(ex); - return individualId; - } - }*/ - @SuppressWarnings("unchecked") public OIDCTransaction getOAuthTransaction(String accessTokenHash) throws Exception { if (cacheManager.getCache(userinfoCache) != null) { - System.out.println("Inside getOAuthTransaction>>>>>>>>"); try { OIDCTransaction oIDCTransaction = cacheManager.getCache(userinfoCache).get(accessTokenHash, OIDCTransaction.class); //NOSONAR getCache() will not be returning null here. - log.info("oIDCTransaction>>>>>>>>", oIDCTransaction); return oIDCTransaction; } catch (Exception e) { log.error("Exception occured while fetching the cache", e); @@ -338,23 +273,7 @@ private String getKeyAlias(String keyAppId, String keyRefId) throws Exception { throw new Exception(NO_UNIQUE_ALIAS); } - private String extractIndividualIdFromStackTrace(Exception ex) { - String stackTrace = getStackTrace(ex); - // Define a regular expression pattern to match the individualId - Pattern pattern = Pattern.compile("individualId=([a-zA-Z0-9_-]+)"); - Matcher matcher = pattern.matcher(stackTrace); - // Find the first occurrence of the pattern - if (matcher.find()) { - return matcher.group(1); // Group 1 contains the matched individualId - } - return null; // Return null if individualId is not found - } - private String getStackTrace(Exception ex) { - StringWriter sw = new StringWriter(); - ex.printStackTrace(new PrintWriter(sw)); - return sw.toString(); - } private byte[] b64Decode(String value) { return urlSafeDecoder.decode(value);