diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml
index da2a570e147..a460d425a99 100644
--- a/.github/workflows/push-trigger.yml
+++ b/.github/workflows/push-trigger.yml
@@ -43,7 +43,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
- OSSRH_URL: ${{ secrets.RELEASE_URL }}
+ OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
diff --git a/authentication/authentication-authtypelockfilter-impl/pom.xml b/authentication/authentication-authtypelockfilter-impl/pom.xml
index c5bacf60c3f..ae96c9ee7be 100644
--- a/authentication/authentication-authtypelockfilter-impl/pom.xml
+++ b/authentication/authentication-authtypelockfilter-impl/pom.xml
@@ -4,9 +4,9 @@
io.mosip.authentication
authentication-parent
- 1.2.0.1-B5
+ 1.2.0.1-SNAPSHOT
- 1.2.0.1-B5
+ 1.2.0.1-SNAPSHOT
authentication-authtypelockfilter-impl
authentication-authtypelockfilter-impl
ID Authentication Filter Implementation for Auth Type Lock validation
diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml
index 4b1774112ed..b2b005e83d4 100644
--- a/authentication/authentication-common/pom.xml
+++ b/authentication/authentication-common/pom.xml
@@ -6,9 +6,9 @@
io.mosip.authentication
authentication-parent
- 1.2.0.1-B5
+ 1.2.0.1-SNAPSHOT
- 1.2.0.1-B5
+ 1.2.0.1-SNAPSHOT
authentication-common
authentication-common
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/IDAMappingConfig.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/IDAMappingConfig.java
index b2f00b47101..3117ec4c3fc 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/IDAMappingConfig.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/IDAMappingConfig.java
@@ -126,4 +126,7 @@ public class IDAMappingConfig implements MappingConfig {
/** The dynamic attributes. */
private Map> dynamicAttributes;
+ /** The password. */
+ private List password;
+
}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/facade/AuthFacadeImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/facade/AuthFacadeImpl.java
index e215a10e3a8..3a3b27878cf 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/facade/AuthFacadeImpl.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/facade/AuthFacadeImpl.java
@@ -29,6 +29,7 @@
import io.mosip.authentication.common.service.helper.AuditHelper;
import io.mosip.authentication.common.service.helper.AuthTransactionHelper;
import io.mosip.authentication.common.service.helper.IdInfoHelper;
+import io.mosip.authentication.common.service.impl.match.IdaIdMapping;
import io.mosip.authentication.common.service.integration.TokenIdManager;
import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager;
import io.mosip.authentication.common.service.util.AuthTypeUtil;
@@ -47,6 +48,7 @@
import io.mosip.authentication.core.indauth.dto.AuthStatusInfo;
import io.mosip.authentication.core.indauth.dto.IdType;
import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO;
+import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO;
import io.mosip.authentication.core.indauth.dto.EkycAuthRequestDTO;
import io.mosip.authentication.core.logger.IdaLogger;
import io.mosip.authentication.core.partner.dto.PartnerPolicyResponseDTO;
@@ -58,6 +60,7 @@
import io.mosip.authentication.core.spi.indauth.service.BioAuthService;
import io.mosip.authentication.core.spi.indauth.service.DemoAuthService;
import io.mosip.authentication.core.spi.indauth.service.OTPAuthService;
+import io.mosip.authentication.core.spi.indauth.service.PasswordAuthService;
import io.mosip.authentication.core.spi.notification.service.NotificationService;
import io.mosip.authentication.core.spi.partner.service.PartnerService;
import io.mosip.kernel.core.logger.spi.Logger;
@@ -129,6 +132,9 @@ public class AuthFacadeImpl implements AuthFacade {
@Autowired
private KeyBindedTokenAuthService keyBindedTokenAuthService;
+
+ @Autowired
+ private PasswordAuthService passwordAuthService;
/*
* (non-Javadoc)
@@ -161,6 +167,14 @@ public AuthResponseDTO authenticateIndividual(AuthRequestDTO authRequestDTO, boo
addKycPolicyAttributes(filterAttributes, kycAuthRequestDTO);
}
+
+ if(authRequestDTO instanceof KycAuthRequestDTO) {
+ KycAuthRequestDTO kycAuthRequestDTO = (KycAuthRequestDTO) authRequestDTO;
+ // In case of kyc-auth request and password auth is requested
+ if(AuthTypeUtil.isPassword(kycAuthRequestDTO)) {
+ filterAttributes.add(IdaIdMapping.PASSWORD.getIdname());
+ }
+ }
Map idResDTO = idService.processIdType(idvIdType, idvid, idInfoHelper.isBiometricDataNeeded(authRequestDTO),
markVidConsumed, filterAttributes);
@@ -312,6 +326,11 @@ private List processAuthType(AuthRequestDTO authRequestDTO,
authTxnBuilder, idvidHash);
}
+ if (!isMatchFailed(authStatusList)) {
+ processPasswordAuth(authRequestDTO, idInfo, token, isAuth, authStatusList, idType, authTokenId, partnerId,
+ authTxnBuilder, idvidHash);
+ }
+
return authStatusList;
}
@@ -383,7 +402,7 @@ private void processDemoAuth(AuthRequestDTO authRequestDTO, Map> idInfo, String token,
+ boolean isAuth, List authStatusList, IdType idType, String authTokenId, String partnerId,
+ AuthTransactionBuilder authTxnBuilder, String idvidHash) throws IdAuthenticationBusinessException {
+ if (AuthTypeUtil.isPassword(authRequestDTO)) {
+ AuthStatusInfo passwordMatchStatus = null;
+ try {
+ passwordMatchStatus = passwordAuthService.authenticate(authRequestDTO, token, idInfo, partnerId);
+ authStatusList.add(passwordMatchStatus);
+
+ boolean isStatus = passwordMatchStatus != null && passwordMatchStatus.isStatus();
+ auditHelper.audit(AuditModules.PASSWORD_AUTH, AuditEvents.PASSWORD_BASED_AUTH_REQUEST, authRequestDTO.getTransactionID(),
+ idType, "authenticateApplicant status(Password) : " + isStatus);
+ } finally {
+ boolean isStatus = passwordMatchStatus != null && passwordMatchStatus.isStatus();
+ logger.info(IdAuthCommonConstants.SESSION_ID, EnvUtil.getAppId(),
+ AUTH_FACADE, "Password Authentication status : " + isStatus);
+ authTxnBuilder.addRequestType(RequestType.PASSWORD_AUTH);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/BaseIDAFilter.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/BaseIDAFilter.java
index 55bf6f085b6..f74ad9f18d8 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/BaseIDAFilter.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/BaseIDAFilter.java
@@ -465,6 +465,12 @@ protected String consumeResponse(ResettableStreamHttpServletRequest requestWrapp
String requestSignature = requestWrapper.getHeader(SIGNATURE);
String responseSignature = null;
if(isSigningRequired()) {
+ if (Objects.isNull(responseAsString) || responseAsString.trim().length() == 0) {
+ mosipLogger.error(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER,
+ " Response String is null or empty for response (JWT) signing");
+ throw new IdAuthenticationAppException(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorCode(),
+ IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorMessage());
+ }
responseSignature = keyManager.signResponse(responseAsString);
responseWrapper.setHeader(EnvUtil.getSignResponse(), responseSignature);
}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/IdAuthFilter.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/IdAuthFilter.java
index 10b4c712394..e9a162fac2c 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/IdAuthFilter.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/filter/IdAuthFilter.java
@@ -28,6 +28,8 @@
import javax.servlet.ServletException;
import io.mosip.authentication.core.indauth.dto.KeyBindedTokenDTO;
+import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -843,6 +845,7 @@ protected void checkAllowedAuthTypeForKeyBindedToken(Map request
Object value = Optional.ofNullable(requestBody.get(IdAuthCommonConstants.REQUEST))
.filter(obj -> obj instanceof Map).map(obj -> ((Map) obj).get(KEY_BINDED_TOKEN))
.filter(obj -> obj instanceof List).orElse(Collections.emptyMap());
+
List list = mapper.readValue(mapper.writeValueAsBytes(value),
new TypeReference>() {
});
@@ -861,6 +864,19 @@ protected void checkAllowedAuthTypeForKeyBindedToken(Map request
}
}
+ protected void checkAllowedAuthTypeForPassword(Map requestBody, List authPolicies)
+ throws IdAuthenticationAppException, IOException {
+ KycAuthRequestDTO authRequestDTO = mapper.readValue(mapper.writeValueAsBytes(requestBody),
+ KycAuthRequestDTO.class);
+
+ if (AuthTypeUtil.isPassword(authRequestDTO) && !isAllowedAuthType(MatchType.Category.PWD.getType(), authPolicies)) {
+ throw new IdAuthenticationAppException(
+ IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorCode(),
+ String.format(IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
+ MatchType.Category.PWD.name()));
+ }
+ }
+
/**
* Check allowed auth type for bio.
*
@@ -1042,16 +1058,25 @@ private void checkAllowedAMRBasedOnClientConfig(Map requestBody,
if (AuthTypeUtil.isPin(authRequestDTO) && !allowedAMRs.contains(MatchType.Category.SPIN.getType())) {
throw new IdAuthenticationAppException(
- IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorCode(),
- String.format(IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
+ IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorCode(),
+ String.format(IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
MatchType.Category.SPIN.name()));
}
if (AuthTypeUtil.isOtp(authRequestDTO) && !allowedAMRs.contains(MatchType.Category.OTP.getType())) {
throw new IdAuthenticationAppException(
- IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorCode(),
- String.format(IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
+ IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorCode(),
+ String.format(IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
MatchType.Category.OTP.name()));
}
+
+ KycAuthRequestDTO kycAuthRequestDTO = mapper.readValue(mapper.writeValueAsBytes(requestBody),
+ KycAuthRequestDTO.class);
+ if (AuthTypeUtil.isPassword(kycAuthRequestDTO) && !allowedAMRs.contains(MatchType.Category.PWD.getType())) {
+ throw new IdAuthenticationAppException(
+ IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorCode(),
+ String.format(IdAuthenticationErrorConstants.OIDC_CLIENT_AUTHTYPE_NOT_ALLOWED.getErrorMessage(),
+ MatchType.Category.PWD.name()));
+ }
checkAllowedAMRForKBT(requestBody, allowedAMRs);
}
} catch (IOException e) {
@@ -1119,19 +1144,28 @@ private Set getAuthenticationFactors(PartnerPolicyResponseDTO partnerPol
* @param requestWrapper the request wrapper
* @return the auth part
*/
- protected Map getAuthPart(ResettableStreamHttpServletRequest requestWrapper) {
+ protected Map getAuthPart(ResettableStreamHttpServletRequest requestWrapper) throws IdAuthenticationAppException{
Map params = new HashMap<>();
String url = requestWrapper.getRequestURL().toString();
String contextPath = requestWrapper.getContextPath();
if ((Objects.nonNull(url) && !url.isEmpty()) && (Objects.nonNull(contextPath) && !contextPath.isEmpty())) {
String[] splitedUrlByContext = url.split(contextPath);
String[] paramsArray = Stream.of(splitedUrlByContext[1].split("/")).filter(str -> !str.isEmpty())
- .toArray(size -> new String[size]);
+ .toArray(size -> new String[size]);
+ mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getCanonicalName(), "getAuthPart",
+ "List of Path Parameters received in url: " + Stream.of(paramsArray).collect(Collectors.joining(", ")));
if (paramsArray.length >= 3) {
params.put(MISPLICENSE_KEY, paramsArray[paramsArray.length - 3]);
params.put(PARTNER_ID, paramsArray[paramsArray.length - 2]);
params.put(API_KEY, paramsArray[paramsArray.length - 1]);
+ } else {
+ mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getCanonicalName(), "getAuthPart",
+ "Required Number of Path Parameters are not available in URL.");
+ throw new IdAuthenticationAppException(
+ IdAuthenticationErrorConstants.URI_PATH_PARAMS_MISSING.getErrorCode(),
+ IdAuthenticationErrorConstants.URI_PATH_PARAMS_MISSING.getErrorMessage());
+
}
}
return params;
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/AuditHelper.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/AuditHelper.java
index 55c9edc9189..bb22b52a9db 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/AuditHelper.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/AuditHelper.java
@@ -1,188 +1,196 @@
-package io.mosip.authentication.common.service.helper;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import io.mosip.authentication.common.service.exception.IdAuthExceptionHandler;
-import io.mosip.authentication.common.service.factory.AuditRequestFactory;
-import io.mosip.authentication.common.service.factory.RestRequestFactory;
-import io.mosip.authentication.common.service.impl.match.BioAuthType;
-import io.mosip.authentication.common.service.util.AuthTypeUtil;
-import io.mosip.authentication.common.service.util.EnvUtil;
-import io.mosip.authentication.core.constant.AuditEvents;
-import io.mosip.authentication.core.constant.AuditModules;
-import io.mosip.authentication.core.constant.RestServicesConstants;
-import io.mosip.authentication.core.dto.AuditRequestDto;
-import io.mosip.authentication.core.exception.IDDataValidationException;
-import io.mosip.authentication.core.exception.IdAuthenticationBaseException;
-import io.mosip.authentication.core.indauth.dto.AuthError;
-import io.mosip.authentication.core.indauth.dto.AuthRequestDTO;
-import io.mosip.authentication.core.indauth.dto.BioIdentityInfoDTO;
-import io.mosip.authentication.core.indauth.dto.IdType;
-import io.mosip.idrepository.core.dto.RestRequestDTO;
-import io.mosip.idrepository.core.helper.RestHelper;
-import io.mosip.kernel.core.http.RequestWrapper;
-
-/**
- * The Class AuditHelper - build audit requests and send it to audit service.
- *
- * @author Manoj SP
- */
-@Component
-public class AuditHelper {
-
- /** The rest helper. */
- @Autowired
- @Qualifier("withSelfTokenWebclient")
- private RestHelper restHelper;
-
- /** The audit factory. */
- @Autowired
- private AuditRequestFactory auditFactory;
-
- /** The rest factory. */
- @Autowired
- private RestRequestFactory restFactory;
-
- @Autowired
- private ObjectMapper mapper;
-
- /** The EnvPropertyResolver */
- @Autowired
- private EnvUtil env;
-
-
- /**
- * Method to build audit requests and send it to audit service.
- *
- * @param module {@link AuditModules}
- * @param event {@link AuditEvents}
- * @param id UIN/VID
- * @param idType {@link IdType} enum
- * @param desc the desc
- * @throws IDDataValidationException the ID data validation exception
- */
- public void audit(AuditModules module, AuditEvents event, String id, IdType idType, String desc)
- throws IDDataValidationException {
- audit(module, event, id, idType.name(), desc);
- }
-
- /**
- * Method to build audit requests and send it to audit service.
- *
- * @param module {@link AuditModules}
- * @param event {@link AuditEvents}
- * @param id UIN/VID
- * @param idType {@link IdType} name
- * @param desc the desc
- * @throws IDDataValidationException the ID data validation exception
- */
- public void audit(AuditModules module, AuditEvents event, String id, String idType, String desc)
- throws IDDataValidationException {
- RequestWrapper auditRequest = auditFactory.buildRequest(module, event, id, idType, desc);
- RestRequestDTO restRequest = restFactory.buildRequest(RestServicesConstants.AUDIT_MANAGER_SERVICE, auditRequest,
- Map.class);
- restHelper.requestAsync(restRequest);
- }
-
- /**
- * Method to build audit error scenarios and send it to audit service.
- *
- * @param module {@link AuditModules}
- * @param event {@link AuditEvents}
- * @param id UIN/VID
- * @param idType {@link IdType} enum
- * @param desc the desc
- * @throws IDDataValidationException the ID data validation exception
- */
- public void audit(AuditModules module, AuditEvents event, String id, IdType idType, IdAuthenticationBaseException e)
- throws IDDataValidationException {
- audit(module, event, id, idType.name(), e);
- }
-
- /**
- * Method to build audit error scenarios and send it to audit service.
- *
- * @param module {@link AuditModules}
- * @param event {@link AuditEvents}
- * @param id UIN/VID
- * @param idType {@link IdType} name
- * @param desc the desc
- * @throws IDDataValidationException the ID data validation exception
- */
- public void audit(AuditModules module, AuditEvents event, String id, String idType, IdAuthenticationBaseException e)
- throws IDDataValidationException {
- List errorList = IdAuthExceptionHandler.getAuthErrors(e);
- String error;
- try {
- error = mapper.writeValueAsString(errorList);
- } catch (JsonProcessingException e1) {
- //Probably will not occur
- error = "Error : " + e.getErrorCode() + " - " + e.getErrorText();
- }
- audit(module, event, id, idType, error);
- }
-
- public void auditExceptionForAuthRequestedModules(AuditEvents authAuditEvent, AuthRequestDTO authRequestDTO,
- IdAuthenticationBaseException e) throws IDDataValidationException {
- List auditModules = getAuditModules(authRequestDTO);
- for (AuditModules auditModule : auditModules) {
- audit(auditModule, authAuditEvent, authRequestDTO.getIndividualId(), authRequestDTO.getIndividualIdType(),
- e);
- }
- }
-
- public void auditStatusForAuthRequestedModules(AuditEvents authAuditEvent, AuthRequestDTO authRequestDTO,
- String status) throws IDDataValidationException {
- List auditModules = getAuditModules(authRequestDTO);
- for (AuditModules auditModule : auditModules) {
- audit(auditModule, authAuditEvent, authRequestDTO.getIndividualId(), authRequestDTO.getIndividualIdType(),
- status);
- }
- }
-
- private List getAuditModules(AuthRequestDTO authRequestDTO) {
- List auditModules = new ArrayList<>(5);
- if (AuthTypeUtil.isOtp(authRequestDTO)) {
- auditModules.add(AuditModules.OTP_AUTH);
- }
-
- if (AuthTypeUtil.isDemo(authRequestDTO)) {
- auditModules.add(AuditModules.DEMO_AUTH);
- }
-
- if (AuthTypeUtil.isPin(authRequestDTO)) {
- auditModules.add(AuditModules.PIN_AUTH);
- }
-
- if (AuthTypeUtil.isBio(authRequestDTO)) {
- if (authRequestDTO.getRequest() != null && authRequestDTO.getRequest().getBiometrics() != null) {
- if ((authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData).anyMatch(
- bioInfo -> BioAuthType.FGR_IMG.getType().equals(bioInfo.getBioType()) || (EnvUtil.getIsFmrEnabled()
- && BioAuthType.FGR_MIN.getType().equals(bioInfo.getBioType()))))) {
- auditModules.add(AuditModules.FINGERPRINT_AUTH);
- }
-
- if (authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData)
- .anyMatch(bioInfo -> BioAuthType.IRIS_IMG.getType().equals(bioInfo.getBioType()))) {
- auditModules.add(AuditModules.IRIS_AUTH);
- }
-
- if (authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData)
- .anyMatch(bioInfo -> BioAuthType.FACE_IMG.getType().equals(bioInfo.getBioType()))) {
- auditModules.add(AuditModules.FACE_AUTH);
- }
- }
- }
- return auditModules;
- }
-
-}
+package io.mosip.authentication.common.service.helper;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.mosip.authentication.common.service.exception.IdAuthExceptionHandler;
+import io.mosip.authentication.common.service.factory.AuditRequestFactory;
+import io.mosip.authentication.common.service.factory.RestRequestFactory;
+import io.mosip.authentication.common.service.impl.match.BioAuthType;
+import io.mosip.authentication.common.service.util.AuthTypeUtil;
+import io.mosip.authentication.common.service.util.EnvUtil;
+import io.mosip.authentication.core.constant.AuditEvents;
+import io.mosip.authentication.core.constant.AuditModules;
+import io.mosip.authentication.core.constant.RestServicesConstants;
+import io.mosip.authentication.core.dto.AuditRequestDto;
+import io.mosip.authentication.core.exception.IDDataValidationException;
+import io.mosip.authentication.core.exception.IdAuthenticationBaseException;
+import io.mosip.authentication.core.indauth.dto.AuthError;
+import io.mosip.authentication.core.indauth.dto.AuthRequestDTO;
+import io.mosip.authentication.core.indauth.dto.BioIdentityInfoDTO;
+import io.mosip.authentication.core.indauth.dto.IdType;
+import io.mosip.idrepository.core.dto.RestRequestDTO;
+import io.mosip.idrepository.core.helper.RestHelper;
+import io.mosip.kernel.core.http.RequestWrapper;
+
+/**
+ * The Class AuditHelper - build audit requests and send it to audit service.
+ *
+ * @author Manoj SP
+ */
+@Component
+public class AuditHelper {
+
+ /** The rest helper. */
+ @Autowired
+ @Qualifier("withSelfTokenWebclient")
+ private RestHelper restHelper;
+
+ /** The audit factory. */
+ @Autowired
+ private AuditRequestFactory auditFactory;
+
+ /** The rest factory. */
+ @Autowired
+ private RestRequestFactory restFactory;
+
+ @Autowired
+ private ObjectMapper mapper;
+
+ /** The EnvPropertyResolver */
+ @Autowired
+ private EnvUtil env;
+
+
+ /**
+ * Method to build audit requests and send it to audit service.
+ *
+ * @param module {@link AuditModules}
+ * @param event {@link AuditEvents}
+ * @param id UIN/VID
+ * @param idType {@link IdType} enum
+ * @param desc the desc
+ * @throws IDDataValidationException the ID data validation exception
+ */
+ public void audit(AuditModules module, AuditEvents event, String id, IdType idType, String desc)
+ throws IDDataValidationException {
+ audit(module, event, id, idType.name(), desc);
+ }
+
+ /**
+ * Method to build audit requests and send it to audit service.
+ *
+ * @param module {@link AuditModules}
+ * @param event {@link AuditEvents}
+ * @param id UIN/VID
+ * @param idType {@link IdType} name
+ * @param desc the desc
+ * @throws IDDataValidationException the ID data validation exception
+ */
+ public void audit(AuditModules module, AuditEvents event, String id, String idType, String desc)
+ throws IDDataValidationException {
+ RequestWrapper auditRequest = auditFactory.buildRequest(module, event, id, idType, desc);
+ RestRequestDTO restRequest = restFactory.buildRequest(RestServicesConstants.AUDIT_MANAGER_SERVICE, auditRequest,
+ Map.class);
+ restHelper.requestAsync(restRequest);
+ }
+
+ /**
+ * Method to build audit error scenarios and send it to audit service.
+ *
+ * @param module {@link AuditModules}
+ * @param event {@link AuditEvents}
+ * @param id UIN/VID
+ * @param idType {@link IdType} enum
+ * @param desc the desc
+ * @throws IDDataValidationException the ID data validation exception
+ */
+ public void audit(AuditModules module, AuditEvents event, String id, IdType idType, IdAuthenticationBaseException e)
+ throws IDDataValidationException {
+ audit(module, event, id, idType.name(), e);
+ }
+
+ /**
+ * Method to build audit error scenarios and send it to audit service.
+ *
+ * @param module {@link AuditModules}
+ * @param event {@link AuditEvents}
+ * @param id UIN/VID
+ * @param idType {@link IdType} name
+ * @param desc the desc
+ * @throws IDDataValidationException the ID data validation exception
+ */
+ public void audit(AuditModules module, AuditEvents event, String id, String idType, IdAuthenticationBaseException e)
+ throws IDDataValidationException {
+ List errorList = IdAuthExceptionHandler.getAuthErrors(e);
+ String error;
+ try {
+ error = mapper.writeValueAsString(errorList);
+ } catch (JsonProcessingException e1) {
+ //Probably will not occur
+ error = "Error : " + e.getErrorCode() + " - " + e.getErrorText();
+ }
+ audit(module, event, id, idType, error);
+ }
+
+ public void auditExceptionForAuthRequestedModules(AuditEvents authAuditEvent, AuthRequestDTO authRequestDTO,
+ IdAuthenticationBaseException e) throws IDDataValidationException {
+ List auditModules = getAuditModules(authRequestDTO);
+ for (AuditModules auditModule : auditModules) {
+ audit(auditModule, authAuditEvent, authRequestDTO.getTransactionID(), authRequestDTO.getIndividualIdType(),
+ e);
+ }
+ }
+
+ public void auditStatusForAuthRequestedModules(AuditEvents authAuditEvent, AuthRequestDTO authRequestDTO,
+ String status) throws IDDataValidationException {
+ List auditModules = getAuditModules(authRequestDTO);
+ for (AuditModules auditModule : auditModules) {
+ audit(auditModule, authAuditEvent, authRequestDTO.getTransactionID(), authRequestDTO.getIndividualIdType(),
+ status);
+ }
+ }
+
+ private List getAuditModules(AuthRequestDTO authRequestDTO) {
+ List auditModules = new ArrayList<>(5);
+ if (AuthTypeUtil.isOtp(authRequestDTO)) {
+ auditModules.add(AuditModules.OTP_AUTH);
+ }
+
+ if (AuthTypeUtil.isDemo(authRequestDTO)) {
+ auditModules.add(AuditModules.DEMO_AUTH);
+ }
+
+ if (AuthTypeUtil.isPin(authRequestDTO)) {
+ auditModules.add(AuditModules.PIN_AUTH);
+ }
+
+ if (AuthTypeUtil.isBio(authRequestDTO)) {
+ if (authRequestDTO.getRequest() != null && authRequestDTO.getRequest().getBiometrics() != null) {
+ if ((authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData).anyMatch(
+ bioInfo -> BioAuthType.FGR_IMG.getType().equals(bioInfo.getBioType()) || (EnvUtil.getIsFmrEnabled()
+ && BioAuthType.FGR_MIN.getType().equals(bioInfo.getBioType()))))) {
+ auditModules.add(AuditModules.FINGERPRINT_AUTH);
+ }
+
+ if (authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData)
+ .anyMatch(bioInfo -> BioAuthType.IRIS_IMG.getType().equals(bioInfo.getBioType()))) {
+ auditModules.add(AuditModules.IRIS_AUTH);
+ }
+
+ if (authRequestDTO.getRequest().getBiometrics().stream().map(BioIdentityInfoDTO::getData)
+ .anyMatch(bioInfo -> BioAuthType.FACE_IMG.getType().equals(bioInfo.getBioType()))) {
+ auditModules.add(AuditModules.FACE_AUTH);
+ }
+ }
+ }
+
+ if (AuthTypeUtil.isKeyBindedToken(authRequestDTO)) {
+ auditModules.add(AuditModules.TOKEN_AUTH);
+ }
+
+ if (AuthTypeUtil.isPassword(authRequestDTO)) {
+ auditModules.add(AuditModules.PASSWORD_AUTH);
+ }
+ return auditModules;
+ }
+
+}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/IdInfoHelper.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/IdInfoHelper.java
index c7293860059..21fdcda6afa 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/IdInfoHelper.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/helper/IdInfoHelper.java
@@ -535,6 +535,12 @@ private Map getEntityInfo(Map> idE
IdAuthenticationErrorConstants.KEY_BINDING_MISSING.getErrorCode(),
String.format(IdAuthenticationErrorConstants.KEY_BINDING_MISSING.getErrorMessage(),
input.getAuthType().getType()));
+
+ case PWD:
+ throw new IdAuthenticationBusinessException(
+ IdAuthenticationErrorConstants.PASSWORD_MISSING.getErrorCode(),
+ String.format(IdAuthenticationErrorConstants.PASSWORD_MISSING.getErrorMessage(),
+ input.getAuthType().getType()));
}
}
return entityInfo;
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdInfoFetcherImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdInfoFetcherImpl.java
index be8c0aa7aea..cdebdf68e2c 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdInfoFetcherImpl.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdInfoFetcherImpl.java
@@ -26,6 +26,7 @@
import io.mosip.authentication.common.service.impl.match.IdaIdMapping;
import io.mosip.authentication.common.service.integration.MasterDataManager;
import io.mosip.authentication.common.service.integration.OTPManager;
+import io.mosip.authentication.common.service.integration.PasswordComparator;
import io.mosip.authentication.common.service.util.BioMatcherUtil;
import io.mosip.authentication.common.service.util.EnvUtil;
import io.mosip.authentication.core.constant.IdAuthCommonConstants;
@@ -37,6 +38,7 @@
import io.mosip.authentication.core.indauth.dto.RequestDTO;
import io.mosip.authentication.core.spi.bioauth.CbeffDocType;
import io.mosip.authentication.core.spi.indauth.match.AuthType;
+import io.mosip.authentication.core.spi.indauth.match.ComparePasswordFunction;
import io.mosip.authentication.core.spi.indauth.match.IdInfoFetcher;
import io.mosip.authentication.core.spi.indauth.match.IdMapping;
import io.mosip.authentication.core.spi.indauth.match.MappingConfig;
@@ -96,6 +98,9 @@ public class IdInfoFetcherImpl implements IdInfoFetcher {
@Autowired(required = false)
private KeyBindedTokenMatcherUtil keyBindedTokenMatcherUtil;
+
+ @Autowired(required = false)
+ private PasswordComparator passwordComparator;
/**
* Gets the demo normalizer.
@@ -572,4 +577,15 @@ public List getUserPreferredLanguages(Map>
}
return Collections.emptyList();
}
+
+ /*
+ * Get Match password Function
+ *
+ * @see io.mosip.authentication.core.spi.indauth.match.IdInfoFetcher#
+ * getMatchPasswordFunction()
+ */
+ @Override
+ public ComparePasswordFunction getMatchPasswordFunction() {
+ return passwordComparator::matchPasswordFunction;
+ }
}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdServiceImpl.java
index fb5949bcd68..452a1c30d14 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdServiceImpl.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/IdServiceImpl.java
@@ -118,7 +118,7 @@ public Map getIdByVid(String vid, boolean isBio, Set fil
public Map processIdType(String idvIdType, String idvId, boolean isBio, boolean markVidConsumed, Set filterAttributes)
throws IdAuthenticationBusinessException {
Map idResDTO = null;
- if (idvIdType.equals(IdType.UIN.getType())) {
+ if (idvIdType.equals(IdType.UIN.getType()) || idvIdType.equals(IdType.HANDLE.getType())) {
try {
idResDTO = getIdByUin(idvId, isBio, filterAttributes);
} catch (IdAuthenticationBusinessException e) {
@@ -205,6 +205,9 @@ public Map getIdentity(String id, boolean isBio, IdType idType,
idType.getType()));
}
+ logger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "getIdentity",
+ "Generated HASHID >> " + hashedId);
+
if (isBio) {
entity = identityRepo.getOne(hashedId);
} else {
@@ -254,6 +257,8 @@ public Map getIdentity(String id, boolean isBio, IdType idType,
}
responseMap.put(TOKEN, entity.getToken());
responseMap.put(ID_HASH, hashedId);
+ logger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "getIdentity",
+ "TOKEN in responseMap >> " + entity.getToken());
return responseMap;
} catch (IOException | DataAccessException | TransactionException | JDBCConnectionException e) {
logger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "getIdentity",
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/PasswordAuthServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/PasswordAuthServiceImpl.java
new file mode 100644
index 00000000000..d337d55c482
--- /dev/null
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/PasswordAuthServiceImpl.java
@@ -0,0 +1,70 @@
+package io.mosip.authentication.common.service.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import io.mosip.authentication.common.service.builder.AuthStatusInfoBuilder;
+import io.mosip.authentication.common.service.builder.MatchInputBuilder;
+import io.mosip.authentication.common.service.config.IDAMappingConfig;
+import io.mosip.authentication.common.service.helper.IdInfoHelper;
+import io.mosip.authentication.common.service.impl.match.PasswordAuthType;
+import io.mosip.authentication.common.service.impl.match.PasswordMatchType;
+import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants;
+import io.mosip.authentication.core.exception.IdAuthenticationBusinessException;
+import io.mosip.authentication.core.indauth.dto.AuthRequestDTO;
+import io.mosip.authentication.core.indauth.dto.AuthStatusInfo;
+import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO;
+import io.mosip.authentication.core.spi.indauth.match.MatchInput;
+import io.mosip.authentication.core.spi.indauth.match.MatchOutput;
+import io.mosip.authentication.core.spi.indauth.service.PasswordAuthService;
+import lombok.NoArgsConstructor;
+
+@Service
+@NoArgsConstructor
+public class PasswordAuthServiceImpl implements PasswordAuthService {
+
+ @Autowired
+ private IdInfoHelper idInfoHelper;
+
+ /** The id info helper. */
+ @Autowired
+ private MatchInputBuilder matchInputBuilder;
+
+ /** The ida mapping config. */
+ @Autowired
+ private IDAMappingConfig idaMappingConfig;
+
+ public AuthStatusInfo authenticate(AuthRequestDTO authRequestDTO,String individualId,
+ Map> idInfo,String partnerId)
+ throws IdAuthenticationBusinessException {
+
+ if (idInfo == null || idInfo.isEmpty()) {
+ throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.SERVER_ERROR);
+ }
+
+ List listMatchInputs = constructMatchInput(authRequestDTO, idInfo);
+
+ List listMatchOutputs = constructMatchOutput(authRequestDTO, listMatchInputs, idInfo,
+ partnerId);
+ // Using AND condition on the match output for Bio auth.
+ boolean isMatched = !listMatchOutputs.isEmpty() && listMatchOutputs.stream().allMatch(MatchOutput::isMatched);
+ return AuthStatusInfoBuilder.buildStatusInfo(isMatched, listMatchInputs, listMatchOutputs,
+ PasswordAuthType.values(), idaMappingConfig);
+
+ }
+
+ public List constructMatchInput(AuthRequestDTO authRequestDTO,
+ Map> idInfo) {
+ return matchInputBuilder.buildMatchInput(authRequestDTO, PasswordAuthType.values(), PasswordMatchType.values(),
+ idInfo);
+ }
+
+ private List constructMatchOutput(AuthRequestDTO authRequestDTO, List listMatchInputs,
+ Map> idInfo, String partnerId)
+ throws IdAuthenticationBusinessException {
+ return idInfoHelper.matchIdentityData(authRequestDTO, idInfo, listMatchInputs, partnerId);
+ }
+}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/IdaIdMapping.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/IdaIdMapping.java
index 789171e659b..4e3ccd80650 100644
--- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/IdaIdMapping.java
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/IdaIdMapping.java
@@ -177,13 +177,14 @@ public String getSubType() {
RIGHTIRIS, LEFTIRIS, UNKNOWN_IRIS,
FACE,UNKNOWN_FACE), "DummyType"),
-
KEY_BINDED_TOKENS("keyBindedTokens"){
public BiFunction> getMappingFunction() {
return (mappingConfig, matchType) -> { return Collections.emptyList(); };
}
},
+ PASSWORD("password", MappingConfig::getPassword),
+
/** The dynamic demographics ID Mapping. */
DYNAMIC("demographics") {
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordAuthType.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordAuthType.java
new file mode 100644
index 00000000000..5c301684adf
--- /dev/null
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordAuthType.java
@@ -0,0 +1,57 @@
+package io.mosip.authentication.common.service.impl.match;
+
+import io.mosip.authentication.common.service.impl.AuthTypeImpl;
+import io.mosip.authentication.core.indauth.dto.AuthRequestDTO;
+import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO;
+import io.mosip.authentication.core.spi.indauth.match.AuthType;
+import io.mosip.authentication.core.spi.indauth.match.ComparePasswordFunction;
+import io.mosip.authentication.core.spi.indauth.match.IdInfoFetcher;
+import io.mosip.authentication.core.spi.indauth.match.MatchType;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+public enum PasswordAuthType implements AuthType {
+
+ PASSWORD(IdaIdMapping.PASSWORD.getIdname(), AuthType.setOf(PasswordMatchType.PASSWORD), "PASSWORD");
+
+ private AuthTypeImpl authTypeImpl;
+
+ /**
+ * Instantiates a new demo auth type.
+ *
+ * @param type the type
+ * @param associatedMatchTypes the associated match types
+ */
+ private PasswordAuthType(String type, Set associatedMatchTypes, String displayName) {
+ authTypeImpl = new AuthTypeImpl(type, associatedMatchTypes, displayName);
+ }
+
+
+ @Override
+ public boolean isAuthTypeInfoAvailable(AuthRequestDTO authRequestDTO) {
+ if(authRequestDTO instanceof KycAuthRequestDTO) {
+ KycAuthRequestDTO kycAuthRequestDTO = (KycAuthRequestDTO) authRequestDTO;
+ return Objects.nonNull(kycAuthRequestDTO.getRequest().getPassword());
+ }
+ return false;
+ }
+
+ @Override
+ public Map getMatchProperties(AuthRequestDTO authRequestDTO, IdInfoFetcher idInfoFetcher,
+ String language) {
+ Map valueMap = new HashMap<>();
+ if(isAuthTypeInfoAvailable(authRequestDTO)) {
+ ComparePasswordFunction func = idInfoFetcher.getMatchPasswordFunction();
+ valueMap.put(IdaIdMapping.PASSWORD.getIdname(), func);
+ }
+ return valueMap;
+ }
+
+ @Override
+ public AuthType getAuthTypeImpl() {
+ return authTypeImpl;
+ }
+}
diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchType.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchType.java
new file mode 100644
index 00000000000..6eee7370204
--- /dev/null
+++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchType.java
@@ -0,0 +1,131 @@
+package io.mosip.authentication.common.service.impl.match;
+
+import static io.mosip.authentication.core.spi.indauth.match.MatchType.setOf;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+import io.mosip.authentication.core.indauth.dto.AuthRequestDTO;
+import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO;
+import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO;
+import io.mosip.authentication.core.indauth.dto.RequestDTO;
+import io.mosip.authentication.core.spi.indauth.match.IdMapping;
+import io.mosip.authentication.core.spi.indauth.match.MatchType;
+import io.mosip.authentication.core.spi.indauth.match.MatchingStrategy;
+import io.mosip.authentication.core.spi.indauth.match.MatchingStrategyType;
+
+public enum PasswordMatchType implements MatchType {
+
+ /** Primary password Match Type. */
+ PASSWORD(IdaIdMapping.PASSWORD, Category.PWD, setOf(PasswordMatchingStrategy.EXACT), authReq -> {
+ KycAuthRequestDTO kycAuthRequestDTO = (KycAuthRequestDTO)authReq;
+ return (Objects.nonNull(kycAuthRequestDTO.getRequest()) &&
+ Objects.nonNull(kycAuthRequestDTO.getRequest().getPassword()))? kycAuthRequestDTO.getRequest().getPassword() : "";
+ });
+
+ /** The allowed matching strategy. */
+ private Set allowedMatchingStrategy;
+
+ /** The request info function. */
+ private Function> requestInfoFunction;
+
+ /** The id mapping. */
+ private IdMapping idMapping;
+
+ private Category category;
+
+ /**
+ * Instantiates a new demo match type.
+ *
+ * @param idMapping the id mapping
+ * @param allowedMatchingStrategy the allowed matching strategy
+ * @param requestInfoFunction the request info function
+ * @param langType the lang type
+ * @param usedBit the used bit
+ * @param matchedBit the matched bit
+ */
+ private PasswordMatchType(IdMapping idMapping, Category category, Set allowedMatchingStrategy,
+ Function requestInfoFunction) {
+ this.idMapping = idMapping;
+ this.category = category;
+ this.requestInfoFunction = (AuthRequestDTO authReq) -> {
+ Map map = new HashMap<>();
+ map.put(idMapping.getIdname(), requestInfoFunction.apply(authReq));
+ return map;
+ };
+ this.allowedMatchingStrategy = Collections.unmodifiableSet(allowedMatchingStrategy);
+ }
+
+ /**
+ * Gets the allowed matching strategy.
+ *
+ * @param matchStrategyType the match strategy type
+ * @return the allowed matching strategy
+ */
+ public Optional getAllowedMatchingStrategy(MatchingStrategyType matchStrategyType) {
+ return allowedMatchingStrategy.stream().filter(ms -> ms.getType().equals(matchStrategyType)).findAny();
+ }
+
+ /**
+ * Gets the entity info.
+ *
+ * @return the entity info
+ */
+ public BiFunction