From 6782b19cc51833b4499984bb92d59fd00f8c0efd Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Tue, 15 Dec 2020 23:46:02 +0100 Subject: implemented CountrySpecificDetailSearchResult, changed datetime to string --- .../v2/dao/CountrySpecificDetailSearchResult.java | 26 ++++++++++++++++++---- .../modules/auth/eidas/v2/dao/SimpleEidasData.java | 9 +------- .../auth/eidas/v2/tasks/InitialSearchTask.java | 17 +++++++++----- .../auth/eidas/v2/utils/EidasResponseUtils.java | 17 ++++++++++++++ 4 files changed, 51 insertions(+), 18 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/CountrySpecificDetailSearchResult.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/CountrySpecificDetailSearchResult.java index 710e286c..b74172f9 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/CountrySpecificDetailSearchResult.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/CountrySpecificDetailSearchResult.java @@ -1,14 +1,32 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.dao; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; + +import java.util.ArrayList; + public class CountrySpecificDetailSearchResult { //TODO is the result the same as the one form the initial search? - int resultsZmr; - int resultsErnb; + ArrayList resultsZmr = new ArrayList<>(); + ArrayList resultsErnb = new ArrayList<>(); public int getResultCount() { - return resultsZmr + resultsErnb; + return resultsZmr.size() + resultsErnb.size(); } - + /** + * Verfies that there is only one match and retunrs the bpk. + * @return bpk bpk of the match + * @throws WorkflowException if multiple results have been found + */ + public String getBpk() throws WorkflowException { + if (getResultCount() != 1) { + throw new WorkflowException("getResultCount() != 1"); + } + if (resultsZmr.size() == 1) { + return resultsZmr.get(0).getBpk(); + } else { + return resultsErnb.get(0).getBpk(); + } + } } 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 c41dd39e..43d85772 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 @@ -26,9 +26,6 @@ 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.Data; -import org.joda.time.DateTime; - -import java.text.SimpleDateFormat; @Data public class SimpleEidasData { @@ -39,7 +36,7 @@ public class SimpleEidasData { private String pseudonym = null; private String givenName = null; private String familyName = null; - private DateTime dateOfBirth = null; + private String dateOfBirth = null; // additional attributes private String placeOfBirth = null; @@ -47,10 +44,6 @@ public class SimpleEidasData { private PostalAddressType address = null; private String taxNumber; - public String getFormatedDateOfBirth() { - return new SimpleDateFormat("yyyy-MM-dd").format(dateOfBirth.toDate()); - } - /** * Compares the register result with the eidas data. * @param result The register data to use for comparison 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 fdf80669..ec56a6dd 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 @@ -180,7 +180,7 @@ public class InitialSearchTask extends AbstractAuthServletTask { eidasAttrMap.get(Constants.eIDAS_ATTR_CURRENTFAMILYNAME))); simpleEidasData.setGivenName(EidasResponseUtils.processGivenName( eidasAttrMap.get(Constants.eIDAS_ATTR_CURRENTGIVENNAME))); - simpleEidasData.setDateOfBirth(EidasResponseUtils.processDateOfBirth( + simpleEidasData.setDateOfBirth(EidasResponseUtils.processDateOfBirthToString( eidasAttrMap.get(Constants.eIDAS_ATTR_DATEOFBIRTH))); // additional attributes @@ -262,12 +262,17 @@ public class InitialSearchTask extends AbstractAuthServletTask { } private String step7a(MergedRegisterSearchResult initialSearchResult, - CountrySpecificDetailSearchResult countrySpecificDetailSearchResult, SimpleEidasData eidData) { + CountrySpecificDetailSearchResult countrySpecificDetailSearchResult, + SimpleEidasData eidData) throws TaskExecutionException { //TODO automerge log.debug("Automerge " + initialSearchResult + " with " + eidData + " " + countrySpecificDetailSearchResult); //TODO - String bpK = "103"; - return bpK; + try { + String bpK = countrySpecificDetailSearchResult.getBpk(); + return bpK; + } catch (WorkflowException e) { + throw new TaskExecutionException(pendingReq, "Step7a failed.", e); + } } private String step8(MergedRegisterSearchResult initialSearchResult, @@ -275,11 +280,11 @@ public class InitialSearchTask extends AbstractAuthServletTask { MergedRegisterSearchResult mdsSearchResult = new MergedRegisterSearchResult(); ArrayList resultsZmr = - zmrClient.searchWithMds(eidData.getGivenName(), eidData.getFamilyName(), eidData.getFormatedDateOfBirth()); + zmrClient.searchWithMds(eidData.getGivenName(), eidData.getFamilyName(), eidData.getDateOfBirth()); mdsSearchResult.setResultsZmr(resultsZmr); ArrayList resultsErnb = - ernbClient.searchWithMds(eidData.getGivenName(), eidData.getFamilyName(), eidData.getFormatedDateOfBirth()); + ernbClient.searchWithMds(eidData.getGivenName(), eidData.getFamilyName(), eidData.getDateOfBirth()); mdsSearchResult.setResultsErnb(resultsErnb); log.debug("Automerge " + initialSearchResult + " with " + eidData + " " + mdsSearchResult); 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 c68a602b..5a1db0e0 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 @@ -23,6 +23,7 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.utils; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -281,6 +282,22 @@ public class EidasResponseUtils { } + /** + * Post-Process the eIDAS DateOfBirth attribute to a string. + * + * @param dateOfBirthObj eIDAS date-of-birth attribute information + * @return formated user's date-of-birth as string + * @throws EidasAttributeException if NO attribute is available + * @throws EidPostProcessingException if post-processing fails + */ + public static String processDateOfBirthToString(Object dateOfBirthObj) throws EidPostProcessingException, + EidasAttributeException { + if (dateOfBirthObj == null || !(dateOfBirthObj instanceof DateTime)) { + throw new EidasAttributeException(Constants.eIDAS_ATTR_DATEOFBIRTH); + } + return new SimpleDateFormat("yyyy-MM-dd").format(((DateTime) dateOfBirthObj).toDate()); + } + /** * Post-Process the eIDAS GivenName attribute. * -- cgit v1.2.3