Skip to content

Commit

Permalink
[ES-482] changed logic to create list object. Change password and sal…
Browse files Browse the repository at this point in the history
…t sharing logic. (#1135)

* Corrected password hash & salt sharing logic.

Signed-off-by: Mahammed Taheer <[email protected]>

* [ES-482] changed logic to create list object.

Signed-off-by: Mahammed Taheer <[email protected]>

---------

Signed-off-by: Mahammed Taheer <[email protected]>
  • Loading branch information
mahammedtaheer authored Nov 28, 2023
1 parent 8e265d5 commit a9daa74
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ protected void checkAllowedAuthTypeForPassword(Map<String, Object> 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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,9 +27,13 @@ public enum PasswordMatchingStrategy implements MatchingStrategy {
ComparePasswordFunction func = (ComparePasswordFunction) object;
Map<String, String> entityInfoMap = (Map<String, String>) entityInfo;
Map<String, String> reqInfoMap = (Map<String, String>) 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<String, String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,5 +21,7 @@
@Repository
public interface OIDCClientDataRepository extends JpaRepository<OIDCClientData, String> {

Optional<OIDCClientData> 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<OIDCClientData> findByClientId(@Param("clientId") String clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -239,7 +240,9 @@ public static Map<String, List<IdentityInfoDTO>> getIdInfo(Map<String, Object> i
return Stream.of(idInfo).collect(Collectors.toList());
} else if (entry.getKey().equals(PASSWORD) && val instanceof Map) {
Map<String, String> map = (Map<String, String>) 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +77,8 @@ public List<String> filterAllowedUserClaims(String oidcClientId, List<String> co
return List.of();
}

List<String> oidcClientAllowedUserClaims = List.of(oidcClientData.get().getUserClaims());
List<String> oidcClientAllowedUserClaims = Stream.of(oidcClientData.get().getUserClaims())
.collect(Collectors.toList());

if (consentAttributes.isEmpty()) {
return oidcClientAllowedUserClaims;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit a9daa74

Please sign in to comment.