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..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,8 +1,14 @@ package io.mosip.authentication.core.util; +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; import org.springframework.stereotype.Component; import io.mosip.authentication.core.constant.IdAuthCommonConstants; @@ -11,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 @@ -19,9 +27,14 @@ @Component public class IdTypeUtil { + private static Logger mosipLogger = IdaLogger.getLogger(IdTypeUtil.class); + @Autowired IdValidationUtil idValidator; + @Value("#{${mosip.ida.handle-types.regex}}") + private Map handleTypesRegex; + public boolean validateUin(String uin) { try { if (Objects.nonNull(idValidator)) @@ -44,11 +57,36 @@ public boolean validateVid(String vid) { } } + public boolean validateHandle(String handle) { + try { + 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)); + } + } catch (BaseUncheckedException e) { + mosipLogger.error(SESSION_ID, this.getClass().getSimpleName(), "VALIDATE_HANDLE", + "Failed to validate handle >> "+ e.getMessage()); + } + 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(), 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, 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-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_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); 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);