Skip to content

Commit

Permalink
ES-421
Browse files Browse the repository at this point in the history
Signed-off-by: ase-101 <[email protected]>
  • Loading branch information
ase-101 committed Dec 13, 2023
1 parent bf1e2ca commit 80e06ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum IdType {
/** The uin. */
UIN("UIN"),
/** The vid. */
VID("VID")
VID("VID"),
HANDLE("HANDLE")
;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +26,9 @@ public class IdTypeUtil {
@Autowired
IdValidationUtil idValidator;

@Value("#{${mosip.ida.handle-types.regex}}")
private Map<String, String> handleTypesRegex;

public boolean validateUin(String uin) {
try {
if (Objects.nonNull(idValidator))
Expand All @@ -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(),
Expand Down

0 comments on commit 80e06ff

Please sign in to comment.