diff options
author | Thomas <> | 2022-10-11 14:09:07 +0200 |
---|---|---|
committer | Thomas <> | 2022-10-11 14:09:07 +0200 |
commit | 1edc816481ac7ee2cbdecbd64f44f367d25fc3bd (patch) | |
tree | 8ac310c17a3d885bc2567c54dc653b44b9eb3b5d /modules/authmodule-eIDAS-v2/src | |
parent | 8a3bdc447d4f95daae9e742c3b7920af243f678c (diff) | |
download | National_eIDAS_Gateway-1edc816481ac7ee2cbdecbd64f44f367d25fc3bd.tar.gz National_eIDAS_Gateway-1edc816481ac7ee2cbdecbd64f44f367d25fc3bd.tar.bz2 National_eIDAS_Gateway-1edc816481ac7ee2cbdecbd64f44f367d25fc3bd.zip |
feat(matching): clearing in case of ZMR and ERnP result contains the same person
In case of KITT between ERnP and ZMR entries it's possible to get the same entity
in both results. Remove ERnP result if ZMR results contains a person with
same bPK.
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src')
2 files changed, 48 insertions, 5 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java index e180e87d..b4f4098e 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java @@ -4,6 +4,8 @@ import java.io.Serializable; import java.math.BigInteger; import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -38,6 +40,9 @@ public class RegisterSearchService { private static final Object ERNP = "ERnP"; private static final String LOG_MSG_RESULTS = "Matching operation: {} results: " + ZMR + ": {} | " + ERNP + ": {}"; + private static final String LOG_MSG_RESULTS_CLEARING = + "Post-processing of register results find duplicated entries. " + + "Remove {} entries from " + ERNP + " result."; private static final String LOG_MSG_KITT = "Matching operation kitts entry on: {}"; @@ -438,9 +443,25 @@ public class RegisterSearchService { result.getPersonResult(), Collections.emptyList()); } - static RegisterStatusResults fromZmrAndErnp(ZmrRegisterResult result, ErnpRegisterResult resultErnp) { + static RegisterStatusResults fromZmrAndErnp(ZmrRegisterResult result, ErnpRegisterResult resultErnp) { + /* + * Post-processing of ERnP entries to remove entities that included twice. + * In case of KITT on register side that KITTS an ERnP to ZMR entry, + * the same entity can part of both responses. + */ + Set<String> existingZmrPersons = result.getPersonResult().stream() + .map(el -> el.getBpk()) + .collect(Collectors.toSet()); + List<RegisterResult> ernpCleared = resultErnp.getPersonResult().stream() + .filter(el -> !existingZmrPersons.contains(el.getBpk())) + .collect(Collectors.toList()); + if (ernpCleared.size() < resultErnp.getPersonResult().size()) { + log.info(LOG_MSG_RESULTS_CLEARING, resultErnp.getPersonResult().size() - ernpCleared.size()); + + } + return new RegisterStatusResults(new RegisterOperationStatus(result.getProcessId()), - result.getPersonResult(), resultErnp.getPersonResult()); + result.getPersonResult(), ernpCleared); } static RegisterStatusResults fromErnp(RegisterOperationStatus status, ErnpRegisterResult updateErnp) { diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java index eef31a02..c9b7b1ac 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java @@ -97,6 +97,7 @@ import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; import eu.eidas.auth.commons.attribute.PersonType; import eu.eidas.auth.commons.light.impl.LightRequest; import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; +import lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { @@ -339,7 +340,7 @@ public class InitialSearchTaskTest { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenReturn(zmrRegisterResult(randomRegisterResult())); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) - .thenReturn(ernpRegisterResult(randomRegisterResult())); + .thenReturn(ernpRegisterResult(randomRegisterResult(RandomStringUtils.randomAlphanumeric(10)))); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -353,6 +354,27 @@ public class InitialSearchTaskTest { } /** + * Find to matches by PersonalId but they are the same person. + */ + @Test + @DirtiesContext + @SneakyThrows + public void samePersonFromZmrAndErnp() { + RegisterResult registerResult = randomRegisterResult(); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(zmrRegisterResult(registerResult)); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(ernpRegisterResult(registerResult)); + + // execute test + task.execute(pendingReq, executionContext); + + // validate state + checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); + + } + + /** * One match by PersonalId, no register update needed */ @Test @@ -545,7 +567,7 @@ public class InitialSearchTaskTest { Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) .thenReturn(emptyErnpRegisterResult()); Mockito.when(ernpClient.searchCountrySpecific(any(), eq(DE))) - .thenReturn(ernpRegisterResult(randomRegisterResult())); + .thenReturn(ernpRegisterResult(randomRegisterResult(RandomStringUtils.randomAlphanumeric(10)))); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); @@ -722,7 +744,7 @@ public class InitialSearchTaskTest { Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)).thenReturn( emptyErnpRegisterResult()); Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate, DE)) - .thenReturn(ernpRegisterResult(randomRegisterResult())); + .thenReturn(ernpRegisterResult(randomRegisterResult(RandomStringUtils.randomAlphanumeric(10)))); Mockito.when(ernpClient.update(any(), any())) .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); |