From f7af2697f4f1606fdd6cda471b87e3b73c95858b Mon Sep 17 00:00:00 2001 From: Shubham Kumar Mishra Date: Thu, 8 Feb 2024 12:24:39 +0530 Subject: [PATCH] missing attribute sp_esvcId added --- .../MyInfoConnectorPROD.properties | 3 +++ .../MyInfoConnectorSANDBOX.properties | 3 +++ .../MyInfoConnectorTEST.properties | 3 +++ .../java/sg/gov/ndi/ApplicationConstant.java | 1 + src/main/java/sg/gov/ndi/MyInfoConnector.java | 25 +++++++++++++------ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Sample Properties/MyInfoConnectorPROD.properties b/Sample Properties/MyInfoConnectorPROD.properties index 39171af..d5fee0c 100755 --- a/Sample Properties/MyInfoConnectorPROD.properties +++ b/Sample Properties/MyInfoConnectorPROD.properties @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST #Client secret provided during onboarding CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2 +#eService Id provided during onboarding +SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM + #Redirect URL for web application REDIRECT_URL=http://localhost:3001/callback diff --git a/Sample Properties/MyInfoConnectorSANDBOX.properties b/Sample Properties/MyInfoConnectorSANDBOX.properties index f6ddc09..6fc97a6 100755 --- a/Sample Properties/MyInfoConnectorSANDBOX.properties +++ b/Sample Properties/MyInfoConnectorSANDBOX.properties @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST #Client secret provided during onboarding CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2 +#eService Id provided during onboarding +SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM + #Redirect URL for web application REDIRECT_URL=http://localhost:3001/callback diff --git a/Sample Properties/MyInfoConnectorTEST.properties b/Sample Properties/MyInfoConnectorTEST.properties index 3f25296..ce4a863 100755 --- a/Sample Properties/MyInfoConnectorTEST.properties +++ b/Sample Properties/MyInfoConnectorTEST.properties @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST #Client secret provided during onboarding CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2 +#eService Id provided during onboarding +SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM + #Redirect URL for web application REDIRECT_URL=http://localhost:3001/callback diff --git a/src/main/java/sg/gov/ndi/ApplicationConstant.java b/src/main/java/sg/gov/ndi/ApplicationConstant.java index 25f210b..5843c1f 100755 --- a/src/main/java/sg/gov/ndi/ApplicationConstant.java +++ b/src/main/java/sg/gov/ndi/ApplicationConstant.java @@ -19,6 +19,7 @@ public final class ApplicationConstant { public static final String ATTRIBUTE = "attributes"; public static final String TRANSACTION_NO = "txnNo"; public static final String RS256 = "RS256"; + public static final String SP_ESVCID = "sp_esvcId"; public static final String AUTHORIZATION_CODE = "authorization_code"; public static final String AUTHORIZATION = "Authorization"; diff --git a/src/main/java/sg/gov/ndi/MyInfoConnector.java b/src/main/java/sg/gov/ndi/MyInfoConnector.java index 2c89a76..e1f7382 100755 --- a/src/main/java/sg/gov/ndi/MyInfoConnector.java +++ b/src/main/java/sg/gov/ndi/MyInfoConnector.java @@ -47,6 +47,7 @@ public class MyInfoConnector { private String privateKeyPwd; private String clientAppId; private String clientAppPwd; + private String spEsvcId; private String redirectUri; private String attributes; private String env; @@ -140,6 +141,11 @@ private void load(Properties prop) throws MyInfoException { } else { this.clientAppPwd = prop.getProperty("CLIENT_SECRET"); } + if (StringUtil.isEmptyAndNull(prop.getProperty("SP_ESERVICES_ID"))) { + throw new MyInfoException("eService Id not found or empty in properties file!"); + } else { + this.spEsvcId = prop.getProperty("SP_ESERVICES_ID"); + } if (StringUtil.isEmptyAndNull(prop.getProperty("REDIRECT_URL"))) { throw new MyInfoException("Redirect url not found or empty in properties file!"); } else { @@ -232,7 +238,7 @@ private void load(Properties prop) throws MyInfoException { */ protected static String getMyInfoPersonData(String authCode, String txnNo, String state, Certificate publicCert, Key privateKey, String clientAppId, String clientAppPwd, String redirectUri, String attributes, - String env, String tokenURL, String personURL, String proxyTokenURL, String proxyPersonURL, String useProxy) + String env, String tokenURL, String personURL, String proxyTokenURL, String proxyPersonURL, String useProxy, String spEsvcId) throws MyInfoException { String result = null; @@ -250,7 +256,7 @@ protected static String getMyInfoPersonData(String authCode, String txnNo, Strin // Get person result = MyInfoConnector.getPersonData(tokenJWT.getSubject(), tokenList.get(ApplicationConstant.ACCESS_TOKEN), - txnNo, personURL, clientAppId, attributes, env, privateKey, proxyPersonURL, useProxy); + txnNo, personURL, clientAppId, attributes, env, privateKey, proxyPersonURL, useProxy, spEsvcId); if (!env.equalsIgnoreCase(ApplicationConstant.SANDBOX)) { @@ -312,7 +318,7 @@ protected String getMyInfoPersonData(String authCode, String txnNo, String state return getMyInfoPersonData(authCode, txnNo, state, myInfoPublicCert, agencyPrivateKey, this.clientAppId, this.clientAppPwd, this.redirectUri, this.attributes, this.env, this.tokenURL, this.personURL, - this.proxyTokenURL, this.proxyPersonURL, this.useProxy); + this.proxyTokenURL, this.proxyPersonURL, this.useProxy, this.spEsvcId); } /** @@ -576,7 +582,7 @@ protected static String getAccessToken(String authCode, String apiURL, String cl * @throws MyInfoException */ protected static String getPersonData(String uinFin, String bearer, String txnNo, String apiURL, String clientAppId, - String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy) + String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy, String spEsvcId) throws MyInfoException { StringBuilder result = new StringBuilder(); @@ -604,6 +610,7 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo baseParams.put(ApplicationConstant.CLIENT_ID + "=", clientAppId); baseParams.put(ApplicationConstant.NONCE + "=", Integer.toString(nonceValue)); baseParams.put(ApplicationConstant.SIGNATURE_METHOD + "=", ApplicationConstant.RS256); + baseParams.put(ApplicationConstant.SP_ESVCID + "=", spEsvcId); baseParams.put(ApplicationConstant.TIMESTAMP + "=", Long.toString(timestamp)); if (txnNo != null) { baseParams.put(ApplicationConstant.TRANSACTION_NO + "=", txnNo); @@ -636,7 +643,9 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo StringBuilder params = new StringBuilder(); params.append(ApplicationConstant.CLIENT_ID).append("=").append(clientAppId).append("&") - .append(ApplicationConstant.ATTRIBUTE).append("=").append(URLEncoder.encode(attributes, StandardCharsets.UTF_8.toString())); + .append(ApplicationConstant.SP_ESVCID).append("=").append(spEsvcId) + .append("&").append(ApplicationConstant.ATTRIBUTE).append("=") + .append(URLEncoder.encode(attributes, StandardCharsets.UTF_8.toString())); if (txnNo != null) { params.append("&").append(ApplicationConstant.TRANSACTION_NO).append("=").append(txnNo); } @@ -707,10 +716,10 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo * @throws MyInfoException */ protected static String getPersonData(String uinFin, String bearer, String personurl, String clientAppId, - String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy) - throws MyInfoException { + String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy, + String spEsvcId) throws MyInfoException { return getPersonData(uinFin, bearer, null, personurl, clientAppId, attributes, env, myinfoPrivateKey, - proxyPersonURL, useProxy); + proxyPersonURL, useProxy, spEsvcId); } }