From 4f937b42a654c436039da4f82e73aa1d4054b817 Mon Sep 17 00:00:00 2001 From: Anusha Sunkada Date: Wed, 13 Dec 2023 18:53:48 +0530 Subject: [PATCH 1/5] ES-421 Update ida-credential_event_store.sql Signed-off-by: Anusha Sunkada Signed-off-by: ase-101 --- db_scripts/mosip_ida/ddl/ida-credential_event_store.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db_scripts/mosip_ida/ddl/ida-credential_event_store.sql b/db_scripts/mosip_ida/ddl/ida-credential_event_store.sql index c589b421f24..f2cc8474bec 100644 --- a/db_scripts/mosip_ida/ddl/ida-credential_event_store.sql +++ b/db_scripts/mosip_ida/ddl/ida-credential_event_store.sql @@ -18,7 +18,7 @@ CREATE TABLE ida.credential_event_store( event_id character varying(36) NOT NULL, event_topic character varying(256) NOT NULL, - credential_transaction_id character varying(36) NOT NULL, + credential_transaction_id character varying(64) NOT NULL, publisher character varying(128), published_on_dtimes timestamp, event_object character varying, From 838ea58f18a769750d9fbeca688e52f6e85326cf Mon Sep 17 00:00:00 2001 From: Anusha Sunkada Date: Wed, 13 Dec 2023 18:57:05 +0530 Subject: [PATCH 2/5] ES-421 renamed file and added alter stmt Signed-off-by: ase-101 --- .../mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql | 1 - .../mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_upgrade.sql | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql create mode 100644 db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_upgrade.sql diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql deleted file mode 100644 index 03dac26391f..00000000000 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql +++ /dev/null @@ -1 +0,0 @@ -\echo 'Upgrade Queries not required for transition from 1.2.0.1-B4 to 1.2.0.1' diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_upgrade.sql new file mode 100644 index 00000000000..36efab138ca --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_upgrade.sql @@ -0,0 +1,3 @@ +\echo 'Upgrade Queries not required for transition from 1.2.0.1-B5 to 1.2.0.1' + +ALTER TABLE ida.credential_event_store ALTER COLUMN credential_transaction_id type character varying(64); From bf1e2cae947ceda980bcb7baa413cbddf95c1e98 Mon Sep 17 00:00:00 2001 From: Anusha Sunkada Date: Wed, 13 Dec 2023 18:58:21 +0530 Subject: [PATCH 3/5] ES-421 Signed-off-by: ase-101 --- .../mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql | 1 - .../mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_rollback.sql | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql create mode 100644 db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_rollback.sql diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql deleted file mode 100644 index 03dac26391f..00000000000 --- a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql +++ /dev/null @@ -1 +0,0 @@ -\echo 'Upgrade Queries not required for transition from 1.2.0.1-B4 to 1.2.0.1' diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_rollback.sql new file mode 100644 index 00000000000..1ea8a6e97f2 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B5_to_1.2.0.1_rollback.sql @@ -0,0 +1,3 @@ +\echo 'Upgrade Queries not required for the transition from 1.2.0.1-B5 to 1.2.0.1' + +ALTER TABLE ida.credential_event_store ALTER COLUMN credential_transaction_id type character varying(36); From 80e06ff369ee64de0c483577f597bd9cb49c7f2e Mon Sep 17 00:00:00 2001 From: ase-101 Date: Wed, 13 Dec 2023 22:14:47 +0530 Subject: [PATCH 4/5] ES-421 Signed-off-by: ase-101 --- .../core/indauth/dto/IdType.java | 3 ++- .../authentication/core/util/IdTypeUtil.java | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/indauth/dto/IdType.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/indauth/dto/IdType.java index 5a6eb8861e9..8831f219dd5 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/indauth/dto/IdType.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/indauth/dto/IdType.java @@ -24,7 +24,8 @@ public enum IdType { /** The uin. */ UIN("UIN"), /** The vid. */ - VID("VID") + VID("VID"), + HANDLE("HANDLE") ; /** diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java index 4767aa7dba8..092c2d95895 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java @@ -1,8 +1,12 @@ package io.mosip.authentication.core.util; +import java.util.List; +import java.util.Map; import java.util.Objects; +import io.mosip.kernel.core.util.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import io.mosip.authentication.core.constant.IdAuthCommonConstants; @@ -22,6 +26,9 @@ public class IdTypeUtil { @Autowired IdValidationUtil idValidator; + @Value("#{${mosip.ida.handle-types.regex}}") + private Map handleTypesRegex; + public boolean validateUin(String uin) { try { if (Objects.nonNull(idValidator)) @@ -44,11 +51,31 @@ public boolean validateVid(String vid) { } } + public boolean validateHandle(String handle) { + if(Objects.nonNull(handleTypesRegex)) { + if(StringUtils.isEmpty(handle)) + return false; + + int index = handle.lastIndexOf("@"); + if(index <= 0) + return false; + + String handleType = handle.substring(index); + if(!handleTypesRegex.containsKey(handleType)) + return false; + + return handle.matches(handleTypesRegex.get(handleType)); + } + return false; + } + public IdType getIdType(String id) throws IdAuthenticationBusinessException { if (this.validateUin(id)) return IdType.UIN; if (this.validateVid(id)) return IdType.VID; + if (this.validateHandle(id)) + return IdType.HANDLE; throw new IdAuthenticationBusinessException( IdAuthenticationErrorConstants.INVALID_INPUT_PARAMETER.getErrorCode(), String.format(IdAuthenticationErrorConstants.INVALID_INPUT_PARAMETER.getErrorMessage(), From bc9ea198a418410d5d2fad88c7ca8f66974a0c53 Mon Sep 17 00:00:00 2001 From: ase-101 Date: Wed, 13 Dec 2023 22:33:20 +0530 Subject: [PATCH 5/5] Fixed review comment Signed-off-by: ase-101 --- .../authentication/core/util/IdTypeUtil.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java index 092c2d95895..7cb5386510a 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/util/IdTypeUtil.java @@ -1,9 +1,11 @@ package io.mosip.authentication.core.util; -import java.util.List; import java.util.Map; import java.util.Objects; +import io.mosip.authentication.core.logger.IdaLogger; +import io.mosip.kernel.core.exception.BaseUncheckedException; +import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -15,6 +17,8 @@ import io.mosip.authentication.core.indauth.dto.IdType; import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; +import static io.mosip.authentication.core.constant.IdAuthCommonConstants.SESSION_ID; + /** * @author Manoj SP * @author Nagarjuna @@ -23,6 +27,8 @@ @Component public class IdTypeUtil { + private static Logger mosipLogger = IdaLogger.getLogger(IdTypeUtil.class); + @Autowired IdValidationUtil idValidator; @@ -52,19 +58,24 @@ public boolean validateVid(String vid) { } public boolean validateHandle(String handle) { - if(Objects.nonNull(handleTypesRegex)) { - if(StringUtils.isEmpty(handle)) - return false; + try { + if(Objects.nonNull(handleTypesRegex)) { + if(StringUtils.isEmpty(handle)) + return false; - int index = handle.lastIndexOf("@"); - if(index <= 0) - return false; + int index = handle.lastIndexOf("@"); + if(index <= 0) + return false; - String handleType = handle.substring(index); - if(!handleTypesRegex.containsKey(handleType)) - return false; + String handleType = handle.substring(index); + if(!handleTypesRegex.containsKey(handleType)) + return false; - return handle.matches(handleTypesRegex.get(handleType)); + return handle.matches(handleTypesRegex.get(handleType)); + } + } catch (BaseUncheckedException e) { + mosipLogger.error(SESSION_ID, this.getClass().getSimpleName(), "VALIDATE_HANDLE", + "Failed to validate handle >> "+ e.getMessage()); } return false; }