Skip to content

Commit

Permalink
Fixed review comment
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 80e06ff commit bc9ea19
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -23,6 +27,8 @@
@Component
public class IdTypeUtil {

private static Logger mosipLogger = IdaLogger.getLogger(IdTypeUtil.class);

@Autowired
IdValidationUtil idValidator;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bc9ea19

Please sign in to comment.