diff options
author | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-22 15:01:35 +0100 |
---|---|---|
committer | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-22 15:04:27 +0100 |
commit | 17205492d16f39009414399a2e17347986b50cbc (patch) | |
tree | ba772c1aceeeb5ff238fa604d2406dc522524ac7 /eidas_modules/authmodule-eIDAS-v2/src/main | |
parent | 0725cce166b91725624e4cde694e9fde4e931bc9 (diff) | |
download | National_eIDAS_Gateway-17205492d16f39009414399a2e17347986b50cbc.tar.gz National_eIDAS_Gateway-17205492d16f39009414399a2e17347986b50cbc.tar.bz2 National_eIDAS_Gateway-17205492d16f39009414399a2e17347986b50cbc.zip |
Refactor storing search results for matching eIDAS data
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main')
3 files changed, 105 insertions, 57 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java index 09af0e24..bab1945a 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java @@ -23,7 +23,6 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernp.IErnpClient; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; @@ -31,11 +30,14 @@ import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper; import at.gv.egiz.eaaf.core.impl.idp.auth.modules.AbstractAuthServletTask; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.DATA_SIMPLE_EIDAS; + /** * Task that searches ErnB and ZMR before adding person to SZR. * @@ -59,8 +61,8 @@ public class CreateNewErnpEntryTask extends AbstractAuthServletTask { public void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException { try { - final AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - SimpleEidasData simpleEidasData = authProcessData.getGenericDataFromSession(Constants.DATA_SIMPLE_EIDAS, + // TODO really the correct key? + SimpleEidasData simpleEidasData = getAuthProcessData().getGenericDataFromSession(DATA_SIMPLE_EIDAS, SimpleEidasData.class); step9CreateNewErnpEntry(simpleEidasData); } catch (final Exception e) { @@ -69,6 +71,11 @@ public class CreateNewErnpEntryTask extends AbstractAuthServletTask { } } + @NotNull + private AuthProcessDataWrapper getAuthProcessData() { + return pendingReq.getSessionData(AuthProcessDataWrapper.class); + } + private void step9CreateNewErnpEntry(SimpleEidasData simpleEidasData) { //TODO can i get bpk from response? diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java index 8a2cac0d..4d5daa6e 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java @@ -54,8 +54,32 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.*; -import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.*; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.DATA_FULL_EIDAS_RESPONSE; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.DATA_INITIAL_REGISTER_RESULT; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.DATA_RESULT_MATCHING_BPK; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.DATA_SIMPLE_EIDAS; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_BIRTHNAME; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_CURRENTADDRESS; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_CURRENTFAMILYNAME; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_CURRENTGIVENNAME; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_DATEOFBIRTH; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_PERSONALIDENTIFIER; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_PLACEOFBIRTH; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_TAXREFERENCE; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processAddress; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processBirthName; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processCountryCode; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processDateOfBirthToString; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processFamilyName; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processGivenName; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processPlaceOfBirth; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processPseudonym; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.processTaxReference; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.translateAddressAttribute; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.translateDateAttribute; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils.translateStringListAttribute; /** * Task that searches registers (ERnP and ZMR) before adding person to SZR. @@ -87,11 +111,9 @@ public class InitialSearchTask extends AbstractAuthServletTask { public void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException { try { - final AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - final SimpleEidasData eidasData = convertEidasAttrToSimpleData(authProcessData); - final String bpk = step2RegisterSearchWithPersonIdentifier(executionContext, eidasData, authProcessData); - authProcessData.setGenericDataToSession(DATA_RESULT_MATCHING_BPK, bpk); - authProcessData.setGenericDataToSession(DATA_SIMPLE_EIDAS, eidasData); + final SimpleEidasData eidasData = convertEidasAttrToSimpleData(); + storeSimpleEidasData(eidasData); + step2RegisterSearchWithPersonIdentifier(executionContext, eidasData); } catch (final TaskExecutionException e) { log.error("Initial search failed", e); throw e; @@ -101,55 +123,58 @@ public class InitialSearchTask extends AbstractAuthServletTask { } } - private String step2RegisterSearchWithPersonIdentifier( - ExecutionContext executionContext, SimpleEidasData eidasData, AuthProcessDataWrapper authProcessData) + private void step2RegisterSearchWithPersonIdentifier( + ExecutionContext executionContext, SimpleEidasData eidasData) throws TaskExecutionException, EaafStorageException, ManualFixNecessaryException { log.trace("Starting step2RegisterSearchWithPersonIdentifier"); String personIdentifier = eidasData.getPseudonym(); MergedRegisterSearchResult registerData = registerSearchService.searchWithPersonIdentifier(eidasData); - authProcessData.setGenericDataToSession(DATA_INITIAL_REGISTER_RESULT, registerData); - switch (registerData.getResultCount()) { - case 0: - return step5CheckAndPerformCountrySpecificSearchIfPossible(executionContext, registerData, eidasData); - case 1: - return step3CheckRegisterUpdateNecessary(registerData, eidasData); - default: - throw new ManualFixNecessaryException(personIdentifier); + storeInitialRegisterResult(registerData); + int resultCount = registerData.getResultCount(); + if (resultCount == 0) { + step5CheckAndPerformCountrySpecificSearchIfPossible(executionContext, registerData, eidasData); + } else if (resultCount == 1) { + step3CheckRegisterUpdateNecessary(registerData, eidasData); + } else { + throw new ManualFixNecessaryException(personIdentifier); } } - private String step3CheckRegisterUpdateNecessary(MergedRegisterSearchResult registerData, SimpleEidasData eidasData) + private void step3CheckRegisterUpdateNecessary(MergedRegisterSearchResult registerData, SimpleEidasData eidasData) throws ManualFixNecessaryException { log.trace("Starting step3CheckRegisterUpdateNecessary"); try { if (eidasData.equalsRegisterData(registerData)) { - return registerData.getBpk(); + String bpk = registerData.getBpk(); + storeMatchingBpk(bpk); } else { - return step4UpdateRegisterData(registerData, eidasData); + step4UpdateRegisterData(registerData, eidasData); } - } catch (WorkflowException e) { + } catch (WorkflowException | EaafStorageException e) { throw new ManualFixNecessaryException(eidasData); } } - private String step4UpdateRegisterData(MergedRegisterSearchResult registerData, SimpleEidasData eidasData) - throws WorkflowException { + private void step4UpdateRegisterData(MergedRegisterSearchResult registerData, SimpleEidasData eidasData) + throws WorkflowException, EaafStorageException { log.trace("Starting step4UpdateRegisterData"); log.debug("Update {} with {}", registerData, eidasData); //TODO wann rechtlich möglich? - return registerData.getBpk(); + String bpk = registerData.getBpk(); + storeMatchingBpk(bpk); } - private String step5CheckAndPerformCountrySpecificSearchIfPossible( - ExecutionContext executionContext, MergedRegisterSearchResult registerData, SimpleEidasData eidasData) - throws TaskExecutionException, ManualFixNecessaryException { + private void step5CheckAndPerformCountrySpecificSearchIfPossible( + ExecutionContext executionContext, MergedRegisterSearchResult registerData, + SimpleEidasData eidasData) + throws TaskExecutionException, ManualFixNecessaryException, EaafStorageException { log.trace("Starting step5CheckAndPerformCountrySpecificSearchIfPossible"); CountrySpecificDetailSearchProcessor specificHandler = findSpecificProcessor(eidasData); if (specificHandler != null) { - return step6CountrySpecificSearch(executionContext, specificHandler, registerData, eidasData); + step6CountrySpecificSearch(executionContext, specificHandler, registerData, eidasData); } else { - return step8RegisterSearchWithMds(executionContext, eidasData); + step8RegisterSearchWithMds(executionContext, eidasData); } } @@ -165,49 +190,67 @@ public class InitialSearchTask extends AbstractAuthServletTask { return null; } - private String step6CountrySpecificSearch(ExecutionContext executionContext, - CountrySpecificDetailSearchProcessor processor, - MergedRegisterSearchResult registerData, - SimpleEidasData eidasData) - throws TaskExecutionException, ManualFixNecessaryException { + private void step6CountrySpecificSearch(ExecutionContext executionContext, + CountrySpecificDetailSearchProcessor processor, + MergedRegisterSearchResult registerData, + SimpleEidasData eidasData) + throws TaskExecutionException, ManualFixNecessaryException, EaafStorageException { log.trace("Starting step6CountrySpecificSearch"); MergedRegisterSearchResult countrySearchResult = processor.search(eidasData); - switch (countrySearchResult.getResultCount()) { - case 0: - return step8RegisterSearchWithMds(executionContext, eidasData); - case 1: - return step7aKittProcess(registerData, countrySearchResult, eidasData); - default: - throw new ManualFixNecessaryException(eidasData); + int resultCount = countrySearchResult.getResultCount(); + if (resultCount == 0) { + step8RegisterSearchWithMds(executionContext, eidasData); + } else if (resultCount == 1) { + step7aKittProcess(registerData, countrySearchResult, eidasData); + } else { + throw new ManualFixNecessaryException(eidasData); } } - private String step7aKittProcess(MergedRegisterSearchResult registerData, - MergedRegisterSearchResult countrySpecificDetailSearchResult, - SimpleEidasData eidasData) throws TaskExecutionException { + private void step7aKittProcess(MergedRegisterSearchResult registerData, + MergedRegisterSearchResult countrySpecificDetailSearchResult, + SimpleEidasData eidasData) + throws TaskExecutionException, EaafStorageException { log.trace("Starting step7aKittProcess"); - return registerSearchService.step7aKittProcess(registerData, countrySpecificDetailSearchResult, + String bpk = registerSearchService.step7aKittProcess(registerData, countrySpecificDetailSearchResult, eidasData, pendingReq); + storeMatchingBpk(bpk); } - private String step8RegisterSearchWithMds(ExecutionContext executionContext, SimpleEidasData eidasData) { + private void step8RegisterSearchWithMds(ExecutionContext executionContext, SimpleEidasData eidasData) + throws EaafStorageException { log.trace("Starting step8RegisterSearchWithMds"); MergedRegisterSearchResult registerData = registerSearchService.searchWithMds(eidasData); if (registerData.getResultCount() == 0) { + // TODO really the correct key to store data? + storeSimpleEidasData(eidasData); executionContext.put(TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true); } else { executionContext.put(TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK, true); } - // todo das suchergebnis auch noch speichern für später! - //TODO implement next phase and return correct value - // TODO what to return? - return null; + } + + private void storeSimpleEidasData(SimpleEidasData eidasData) throws EaafStorageException { + getAuthProcessData().setGenericDataToSession(DATA_SIMPLE_EIDAS, eidasData); + } + + private void storeInitialRegisterResult(MergedRegisterSearchResult registerData) throws EaafStorageException { + getAuthProcessData().setGenericDataToSession(DATA_INITIAL_REGISTER_RESULT, registerData); + } + + private void storeMatchingBpk(String bpk) throws EaafStorageException { + getAuthProcessData().setGenericDataToSession(DATA_RESULT_MATCHING_BPK, bpk); + } + + @NotNull + private AuthProcessDataWrapper getAuthProcessData() { + return pendingReq.getSessionData(AuthProcessDataWrapper.class); } @NotNull - private SimpleEidasData convertEidasAttrToSimpleData(AuthProcessDataWrapper authProcessData) + private SimpleEidasData convertEidasAttrToSimpleData() throws EidasAttributeException { - final ILightResponse eidasResponse = authProcessData + final ILightResponse eidasResponse = getAuthProcessData() .getGenericDataFromSession(DATA_FULL_EIDAS_RESPONSE, ILightResponse.class); Map<String, Object> simpleMap = convertEidasAttrToSimpleMap(eidasResponse.getAttributes().getAttributeMap()); return convertSimpleMapToSimpleData(simpleMap); diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java index 010681a9..94b85b7c 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java @@ -47,8 +47,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_PERSONALIDENTIFIER; - public class EidasResponseUtils { private static final Logger log = LoggerFactory.getLogger(EidasResponseUtils.class); public static final String PERSONALIDENIFIER_VALIDATION_PATTERN = "^[A-Z,a-z]{2}/[A-Z,a-z]{2}/.*"; |