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 9796bed5cff..2dd03849495 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 @@ -869,7 +869,7 @@ protected void checkAllowedAuthTypeForPassword(Map requestBody, KycAuthRequestDTO authRequestDTO = mapper.readValue(mapper.writeValueAsBytes(requestBody), KycAuthRequestDTO.class); - if (AuthTypeUtil.isPassword(authRequestDTO) && !isAllowedAuthType(MatchType.Category.PASSWORD.getType(), authPolicies)) { + if (AuthTypeUtil.isPassword(authRequestDTO) && !isAllowedAuthType(MatchType.Category.PASSWORD.getType(), authPolicies)) { throw new IdAuthenticationAppException( IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorCode(), String.format(IdAuthenticationErrorConstants.AUTHTYPE_NOT_ALLOWED.getErrorMessage(), diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchingStrategy.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchingStrategy.java index 723a95279c9..a567dedf1fe 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchingStrategy.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/match/PasswordMatchingStrategy.java @@ -1,8 +1,11 @@ package io.mosip.authentication.common.service.impl.match; import static io.mosip.authentication.core.constant.IdAuthCommonConstants.SEMI_COLON; +import static io.mosip.authentication.core.constant.IdAuthCommonConstants.COLON; +import java.util.Arrays; import java.util.Map; +import java.util.stream.Collectors; import io.mosip.authentication.core.constant.IdAuthCommonConstants; import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; @@ -24,9 +27,13 @@ public enum PasswordMatchingStrategy implements MatchingStrategy { ComparePasswordFunction func = (ComparePasswordFunction) object; Map entityInfoMap = (Map) entityInfo; Map reqInfoMap = (Map) reqInfo; - String[] hashSaltValue = entityInfoMap.get("password").split(SEMI_COLON); - String passwordHashedValue = hashSaltValue[0]; - String salt = hashSaltValue[1]; + String hashSaltValue = entityInfoMap.get(IdaIdMapping.PASSWORD.getIdname()); + Map passwordMap = Arrays.stream(hashSaltValue.split(SEMI_COLON)) + .map(str -> str.split(String.valueOf(COLON), 2)) + .collect(Collectors.toMap(strArr -> strArr[0].trim(), strArr -> strArr[1].trim())); + + String passwordHashedValue = passwordMap.get(IdAuthCommonConstants.HASH); + String salt = passwordMap.get(IdAuthCommonConstants.SALT); String reqInfoValue = reqInfoMap.get(IdaIdMapping.PASSWORD.getIdname()); boolean matched = func.matchPasswordFunction(reqInfoValue, passwordHashedValue, salt); return !matched ? 0 : 100; diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OIDCClientDataRepository.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OIDCClientDataRepository.java index 22e2fc14412..f4b6143408b 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OIDCClientDataRepository.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OIDCClientDataRepository.java @@ -1,8 +1,13 @@ package io.mosip.authentication.common.service.repository; +import static io.mosip.authentication.core.constant.IdAuthCommonConstants.OIDC_CLIENT_DATA; + import java.util.Optional; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import io.mosip.authentication.common.service.entity.OIDCClientData; @@ -16,5 +21,7 @@ @Repository public interface OIDCClientDataRepository extends JpaRepository { - Optional findByClientId(String clientId); + @Cacheable(value = OIDC_CLIENT_DATA, key="#oidc_client_id", condition="#oidc_client_id!=null") + @Query("select oi from OIDCClientData oi where oi.clientId = :clientId") + Optional findByClientId(@Param("clientId") String clientId); } diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java index 04f3fc39f0c..94f2e1ea739 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java @@ -449,8 +449,12 @@ public final class IdAuthCommonConstants { public static final String PASSWORD = "password"; + public static final String SALT = "salt"; + public static final String SEMI_COLON = ";"; + public static final String OIDC_CLIENT_DATA = "oidc_client_data"; + private IdAuthCommonConstants() { } } diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/IdInfoFetcher.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/IdInfoFetcher.java index 2d168eeb52e..237e97b6a22 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/IdInfoFetcher.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/IdInfoFetcher.java @@ -2,6 +2,7 @@ import static io.mosip.authentication.core.constant.IdAuthCommonConstants.PASSWORD; import static io.mosip.authentication.core.constant.IdAuthCommonConstants.SEMI_COLON; +import static io.mosip.authentication.core.constant.IdAuthCommonConstants.COLON; import java.util.Collections; import java.util.List; @@ -239,7 +240,9 @@ public static Map> getIdInfo(Map i return Stream.of(idInfo).collect(Collectors.toList()); } else if (entry.getKey().equals(PASSWORD) && val instanceof Map) { Map map = (Map) val; - String passwordData = map.entrySet().stream().map(mapEntry -> mapEntry.getValue() ).collect(Collectors.joining(SEMI_COLON)); + String passwordData = map.entrySet().stream() + .map(mapEntry -> mapEntry.getKey().trim() + String.valueOf(COLON) + mapEntry.getValue().trim()) + .collect(Collectors.joining(SEMI_COLON)); IdentityInfoDTO idInfo = new IdentityInfoDTO(); idInfo.setValue(String.valueOf(passwordData)); return Stream.of(idInfo).collect(Collectors.toList()); diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/util/ExchangeDataAttributesUtil.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/util/ExchangeDataAttributesUtil.java index 73a86159bff..477ce9b5568 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/util/ExchangeDataAttributesUtil.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/util/ExchangeDataAttributesUtil.java @@ -5,6 +5,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -76,7 +77,8 @@ public List filterAllowedUserClaims(String oidcClientId, List co return List.of(); } - List oidcClientAllowedUserClaims = List.of(oidcClientData.get().getUserClaims()); + List oidcClientAllowedUserClaims = Stream.of(oidcClientData.get().getUserClaims()) + .collect(Collectors.toList()); if (consentAttributes.isEmpty()) { return oidcClientAllowedUserClaims; diff --git a/authentication/esignet-integration-impl/src/main/java/io/mosip/authentication/esignet/integration/service/IdaKeyBinderImpl.java b/authentication/esignet-integration-impl/src/main/java/io/mosip/authentication/esignet/integration/service/IdaKeyBinderImpl.java index 245a7821ebf..2848be4f3cb 100644 --- a/authentication/esignet-integration-impl/src/main/java/io/mosip/authentication/esignet/integration/service/IdaKeyBinderImpl.java +++ b/authentication/esignet-integration-impl/src/main/java/io/mosip/authentication/esignet/integration/service/IdaKeyBinderImpl.java @@ -6,22 +6,14 @@ package io.mosip.authentication.esignet.integration.service; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.mosip.authentication.esignet.integration.dto.*; -import io.mosip.esignet.api.dto.AuthChallenge; -import io.mosip.esignet.api.dto.KeyBindingResult; -import io.mosip.esignet.api.dto.SendOtpResult; -import io.mosip.esignet.api.exception.KeyBindingException; -import io.mosip.esignet.api.exception.KycAuthException; -import io.mosip.esignet.api.exception.SendOtpException; -import io.mosip.esignet.api.spi.KeyBinder; -import io.mosip.esignet.api.util.ErrorConstants; -import lombok.extern.slf4j.Slf4j; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; @@ -32,10 +24,20 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.mosip.authentication.esignet.integration.dto.IdaResponseWrapper; +import io.mosip.authentication.esignet.integration.dto.IdaSendOtpRequest; +import io.mosip.authentication.esignet.integration.dto.KeyBindingRequest; +import io.mosip.authentication.esignet.integration.dto.KeyBindingResponse; +import io.mosip.esignet.api.dto.AuthChallenge; +import io.mosip.esignet.api.dto.KeyBindingResult; +import io.mosip.esignet.api.dto.SendOtpResult; +import io.mosip.esignet.api.exception.KeyBindingException; +import io.mosip.esignet.api.exception.SendOtpException; +import io.mosip.esignet.api.spi.KeyBinder; +import io.mosip.esignet.api.util.ErrorConstants; +import lombok.extern.slf4j.Slf4j; @ConditionalOnProperty(value = "mosip.esignet.integration.key-binder", havingValue = "IdaKeyBinderImpl") @Component