From 8c13c21799beed76eea848504677eb935026397c Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Thu, 25 Feb 2021 11:18:44 +0100 Subject: Implement and test ReceiveAustrianResidenceGuiResponseTask --- .../modules/auth/eidas/v2/dao/RegisterResult.java | 10 +- .../modules/auth/eidas/v2/dao/SimpleEidasData.java | 4 + .../eidas/v2/service/RegisterSearchService.java | 7 ++ .../ReceiveAustrianResidenceGuiResponseTask.java | 138 +++++++++++++-------- .../modules/auth/eidas/v2/zmr/DummyZmrClient.java | 6 + .../modules/auth/eidas/v2/zmr/IZmrClient.java | 3 + 6 files changed, 114 insertions(+), 54 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java index 1cc36fe9..4674751d 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java @@ -24,9 +24,15 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.dao; import at.gv.e_government.reference.namespace.persondata._20020228.PostalAddressType; -import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; -@Data +@Getter +@NoArgsConstructor +@ToString +@EqualsAndHashCode public class RegisterResult { // MDS diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java index 84327941..f60a9906 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java @@ -25,10 +25,14 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.dao; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; import at.gv.e_government.reference.namespace.persondata._20020228.PostalAddressType; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.apache.commons.lang3.builder.EqualsBuilder; @Data +@AllArgsConstructor +@NoArgsConstructor public class SimpleEidasData { private String citizenCountryCode; diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java index 6a41893b..fad985c2 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/service/RegisterSearchService.java @@ -11,6 +11,7 @@ import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.List; @Slf4j @@ -38,6 +39,7 @@ public class RegisterSearchService { public String step7aKittProcess(MergedRegisterSearchResult initialSearchResult, MergedRegisterSearchResult specificDetailSearchResult, SimpleEidasData eidasData, IRequest pendingReq) throws TaskExecutionException { + // TODO verify with which data this method gets called try { if (initialSearchResult.getResultCount() != 0) { throw new WorkflowException("initialSearchResult.getResultCount() != 0"); @@ -107,4 +109,9 @@ public class RegisterSearchService { List resultsErnp = ernpClient.searchWithBpkZp(bpkZp); return new MergedRegisterSearchResult(resultsZmr, resultsErnp); } + + public MergedRegisterSearchResult searchWithResidence(String zipcode, String city, String street) { + List resultsZmr = zmrClient.searchWithResidenceData(zipcode, city, street); + return new MergedRegisterSearchResult(resultsZmr, Collections.emptyList()); + } } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java index 7dcf62ac..d565c329 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java @@ -24,94 +24,128 @@ 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.MergedRegisterSearchResult; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.InvalidUserInputException; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.IZmrClient; -import at.gv.egiz.eaaf.core.api.data.EaafConstants; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ManualFixNecessaryException; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; 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.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Enumeration; +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_SIMPLE_EIDAS; + /** * Task receives the response of {@link GenerateAustrianResidenceGuiTask} and handles it. + * This corresponds to Steps 17B, 18, 19 in the eIDAS Matching Concept. * * @author amarsalek + * @author ckollmann */ @Slf4j @Component("ReceiveAustrianResidenceGuiResponseTask") public class ReceiveAustrianResidenceGuiResponseTask extends AbstractAuthServletTask { - final String formerResidenceAvailableParameterName = "formerResidenceAvailable"; - final String streetParameterName = "street"; - final String zipCodeParameterName = "zipcode"; - final String cityParameterName = "city"; - private final IZmrClient zmrClient; + public static final String PARAM_FORMER_RESIDENCE_AVAILABLE = "formerResidenceAvailable"; + public static final String PARAM_STREET = "street"; + public static final String PARAM_CITY = "city"; + public static final String PARAM_ZIPCODE = "zipcode"; + private final RegisterSearchService registerSearchService; + + public ReceiveAustrianResidenceGuiResponseTask(RegisterSearchService registerSearchService) { + this.registerSearchService = registerSearchService; + } - public ReceiveAustrianResidenceGuiResponseTask(IZmrClient zmrClient) { - this.zmrClient = zmrClient; + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class UserInput { + private boolean formerResidenceAvailable; + private String zipcode; + private String city; + private String street; } - //TODO @Override public void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException { - log.trace("Starting ReceiveAustrianResidenceGuiResponseTask"); - // set parameter execution context - final Enumeration reqParamNames = request.getParameterNames(); - String street = null; - String city = null; - String zipcode = null; - Boolean formerResidenceAvailable = false; - while (reqParamNames.hasMoreElements()) { - final String paramName = reqParamNames.nextElement(); - if (StringUtils.isNotEmpty(paramName) - && !EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName) - && formerResidenceAvailableParameterName.equalsIgnoreCase(paramName)) { - formerResidenceAvailable = - Boolean.parseBoolean(StringEscapeUtils.escapeHtml(request.getParameter(paramName))); - } - if (StringUtils.isNotEmpty(paramName) - && !EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName) - && streetParameterName.equalsIgnoreCase(paramName)) { - street = StringEscapeUtils.escapeHtml(request.getParameter(paramName)); - } - if (StringUtils.isNotEmpty(paramName) - && !EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName) - && cityParameterName.equalsIgnoreCase(paramName)) { - city = StringEscapeUtils.escapeHtml(request.getParameter(paramName)); - } - if (StringUtils.isNotEmpty(paramName) - && !EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName) - && zipCodeParameterName.equalsIgnoreCase(paramName)) { - zipcode = StringEscapeUtils.escapeHtml(request.getParameter(paramName)); - } - } - if (formerResidenceAvailable) { - //step 18 - if (street.isEmpty() || city.isEmpty() || zipcode.isEmpty()) { - //form should ensure that mandatory fields are field => - //this can never happen, expect somebody manipulated the response + UserInput input = parseHtmlInput(request); + if (input.isFormerResidenceAvailable()) { + if (input.getStreet().isEmpty() || input.getCity().isEmpty() || input.getZipcode().isEmpty()) { + // form should ensure that mandatory fields are field => this should never happen throw new TaskExecutionException(pendingReq, "Invalid user input", new InvalidUserInputException()); } - step18_RegisterSearch(street, city, zipcode);//TODO also MDS? + // TODO Also search with MDS? + MergedRegisterSearchResult result = registerSearchService + .searchWithResidence(input.zipcode, input.city, input.street); + if (result.getResultCount() == 0) { + moveToNextTask(executionContext); + return; + } else if (result.getResultCount() == 1) { + compareSearchResultWithInitialData(executionContext, result); + } else { + throw new TaskExecutionException(pendingReq, "Manual Fix necessary", new ManualFixNecessaryException("todo")); + } } else { - //step 20 or for now (phase 1) step 9 - executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true); + moveToNextTask(executionContext); } + } + private void compareSearchResultWithInitialData(ExecutionContext executionContext, MergedRegisterSearchResult result) + throws TaskExecutionException { + try { + AuthProcessDataWrapper authProcessDataWrapper = pendingReq.getSessionData(AuthProcessDataWrapper.class); + MergedRegisterSearchResult initialSearchResult = authProcessDataWrapper + .getGenericDataFromSession(DATA_INITIAL_REGISTER_RESULT, MergedRegisterSearchResult.class); + SimpleEidasData simpleEidasData = authProcessDataWrapper + .getGenericDataFromSession(DATA_SIMPLE_EIDAS, SimpleEidasData.class); + if (simpleEidasData.equalsRegisterData(result)) { + registerSearchService.step7aKittProcess(initialSearchResult, result, simpleEidasData, pendingReq); + } else { + moveToNextTask(executionContext); + } + } catch (WorkflowException e) { + throw new TaskExecutionException(pendingReq, "Search failed", new ManualFixNecessaryException("todo")); + } + } + private void moveToNextTask(ExecutionContext executionContext) { + // Later on, this should transition to Step 20 + executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true); } - private void step18_RegisterSearch(String street, String city, String zipcode) { - System.out.println(street + city + zipcode + zmrClient);//TODO + private @NotNull UserInput parseHtmlInput(HttpServletRequest request) { + Enumeration reqParamNames = request.getParameterNames(); + UserInput result = new UserInput(); + while (reqParamNames.hasMoreElements()) { + final String paramName = reqParamNames.nextElement(); + String escaped = StringEscapeUtils.escapeHtml(request.getParameter(paramName)); + if (PARAM_FORMER_RESIDENCE_AVAILABLE.equalsIgnoreCase(paramName)) { + result.setFormerResidenceAvailable(Boolean.parseBoolean(escaped)); + } else if (PARAM_STREET.equalsIgnoreCase(paramName)) { + result.setStreet(escaped); + } else if (PARAM_CITY.equalsIgnoreCase(paramName)) { + result.setCity(escaped); + } else if (PARAM_ZIPCODE.equalsIgnoreCase(paramName)) { + result.setZipcode(escaped); + } + } + return result; } } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/DummyZmrClient.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/DummyZmrClient.java index 87b00f07..80e61451 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/DummyZmrClient.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/DummyZmrClient.java @@ -68,4 +68,10 @@ public class DummyZmrClient implements IZmrClient { return Collections.emptyList(); } + @Override + public List searchWithResidenceData(String zipcode, String city, String street) { + // TODO + return Collections.emptyList(); + } + } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/IZmrClient.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/IZmrClient.java index 2742ae31..5ca69d3d 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/IZmrClient.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/zmr/IZmrClient.java @@ -42,4 +42,7 @@ public interface IZmrClient { void update(RegisterResult registerResult, SimpleEidasData eidData); List searchWithBpkZp(String bpkzp); + + List searchWithResidenceData(String zipcode, String city, String street); + } -- cgit v1.2.3