diff options
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java | 111 |
1 files changed, 85 insertions, 26 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java index 58b3ca45..15b7573c 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java @@ -38,8 +38,10 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData.SimpleEidasDataBuilder; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.api.DefaultApi; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.invoker.ApiClient; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.Aendern; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.AendernResponse; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.AnlegenResponse; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.Eidas; @@ -49,6 +51,7 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.PersonAen import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.PersonAnlegen; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.PersonSuchen; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.Personendaten; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.PersonendatenErgebnis; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.SuchEidas; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.Suchdaten; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ernp.model.SuchenResponse; @@ -247,10 +250,11 @@ public class ErnpRestClient implements IErnpClient { // select elements that have to be updated Collection<? extends Eidas> eidasDocumentToAdd = - selectEidasDocumentsToAdd(ernpPersonToKitt, eidData); + selectEidasDocumentsToAdd(ernpPersonToKitt, eidData); + SimpleEidasData mdsToUpdate = selectMdsInformationToUpdate(ernpPersonToKitt, eidData); - if (eidasDocumentToAdd.isEmpty()) { - log.info("Find no eIDAS document for update during: {}. Looks strange but nothing todo", + if (eidasDocumentToAdd.isEmpty() && mdsToUpdate == null) { + log.info("Find no eIDAS document or MDS for update during: {}. Nothing todo on ERnP side", PROCESS_KITT_GENERAL); return new ErnpRegisterResult(Arrays.asList(registerResult)); @@ -258,7 +262,7 @@ public class ErnpRestClient implements IErnpClient { log.info("Find #{} eIDAS documents for update during: {}", eidasDocumentToAdd.size(), PROCESS_KITT_GENERAL); // update entry based on selected update info's and results from search response - return updatePersonInErnp(ernpPersonToKitt, eidasDocumentToAdd, eidData.getCitizenCountryCode()); + return updatePersonInErnp(ernpPersonToKitt, eidasDocumentToAdd, mdsToUpdate, eidData.getCitizenCountryCode()); } @@ -430,27 +434,8 @@ public class ErnpRestClient implements IErnpClient { } - /** - * Build AT specific Date String 'yyyy-MM-dd' from ERnP birthday representation. - * - * <p> - * <b>Info:</b> {@link LocalDate} can not be used, because '1940-00-00' is also - * a valid birthday on ERnP site. - * </p> - * - * @param geburtsdatum ERnP birthday representation - * @return birthday in 'yyyy-MM-dd' format - */ - private String getTextualBirthday(PartialDate geburtsdatum) { - return MessageFormat.format("{0}-{1}-{2}", - String.valueOf(geburtsdatum.getJahr()), - String.format("%02d", geburtsdatum.getMonat()), - String.format("%02d", geburtsdatum.getTag())); - - } - private ErnpRegisterResult updatePersonInErnp(Person ernpPersonToKitt, - Collection<? extends Eidas> eidasDocumentToAdd, String citizenCountryCode) + Collection<? extends Eidas> eidasDocumentToAdd, SimpleEidasData mdsToUpdate, String citizenCountryCode) throws ServiceFault { // build generic request metadata final GenericRequestParams generic = buildGenericRequestParameters("stepKittUpdate"); @@ -466,8 +451,12 @@ public class ErnpRestClient implements IErnpClient { // add new eIDAS attributes eidasDocumentToAdd.stream().forEach(el -> ernpReq.getAnlegen().addEidasItem(el)); - // TODO: should we update MDS also in that step? - + // update MDS if required + if (mdsToUpdate != null) { + log.debug("Find MDS to update. Injection update entries into ERnP request ... "); + ernpReq.setAendern(generateMdsChangeRequest(ernpPersonToKitt, mdsToUpdate)); + + } // request ERnP log.trace("Requesting ERnP for '{}' operation", PROCESS_KITT_IDENITIES_UPDATE); @@ -604,6 +593,56 @@ public class ErnpRestClient implements IErnpClient { return el; } + private SimpleEidasData selectMdsInformationToUpdate(Person ernpPersonToKitt, SimpleEidasData eidData) { + PersonendatenErgebnis person = ernpPersonToKitt.getPersonendaten(); + SimpleEidasDataBuilder builder = SimpleEidasData.builder(); + + boolean findMismatch = false; + if (!person.getVorname().equals(eidData.getGivenName())) { + findMismatch = true; + builder.givenName(eidData.getGivenName()); + + } + + if (!person.getFamilienname().equals(eidData.getFamilyName())) { + findMismatch = true; + builder.familyName(eidData.getFamilyName()); + + } + + if (!getTextualBirthday(person.getGeburtsdatum()).equals(eidData.getDateOfBirth())) { + findMismatch = true; + builder.dateOfBirth(eidData.getDateOfBirth()); + + } + + return findMismatch ? builder.build() : null; + } + + private Aendern generateMdsChangeRequest(Person ernpPersonToKitt, SimpleEidasData mdsToUpdate) { + Aendern el = new Aendern(); + Personendaten person = new Personendaten(); + person.setEntityId(ernpPersonToKitt.getPersonendaten().getEntityId()); + el.setPersonendaten(person); + + if (StringUtils.isNotEmpty(mdsToUpdate.getFamilyName())) { + person.setFamilienname(mdsToUpdate.getFamilyName()); + + } + + if (StringUtils.isNotEmpty(mdsToUpdate.getGivenName())) { + person.setVorname(mdsToUpdate.getGivenName()); + + } + + if (StringUtils.isNotEmpty(mdsToUpdate.getDateOfBirth())) { + person.setGeburtsdatum(buildErnpBirthday(mdsToUpdate.getDateOfBirth())); + + } + return el; + + } + /** * Map an AT specific Date String 'yyyy-MM-dd' to ERnP birthday representation. * @@ -626,6 +665,26 @@ public class ErnpRestClient implements IErnpClient { return result; } + + /** + * Build AT specific Date String 'yyyy-MM-dd' from ERnP birthday representation. + * + * <p> + * <b>Info:</b> {@link LocalDate} can not be used, because '1940-00-00' is also + * a valid birthday on ERnP site. + * </p> + * + * @param geburtsdatum ERnP birthday representation + * @return birthday in 'yyyy-MM-dd' format + */ + private String getTextualBirthday(PartialDate geburtsdatum) { + return MessageFormat.format("{0}-{1}-{2}", + String.valueOf(geburtsdatum.getJahr()), + String.format("%02d", geburtsdatum.getMonat()), + String.format("%02d", geburtsdatum.getTag())); + + } + /** * Get all eIDAS document with the specified country code and document type. |