From 80e06ff369ee64de0c483577f597bd9cb49c7f2e Mon Sep 17 00:00:00 2001 From: ase-101 Date: Wed, 13 Dec 2023 22:14:47 +0530 Subject: [PATCH] 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(),