diff options
author | Thomas <> | 2023-02-27 14:42:29 +0100 |
---|---|---|
committer | Thomas <> | 2023-02-27 14:42:29 +0100 |
commit | 691356756910253d77fbcdd3d58ce3051776cc5f (patch) | |
tree | 5c17004a73a5af92f9bc4190a9a8675346929712 /modules/authmodule-eIDAS-v2/src/main/java | |
parent | b732517662feb33f39f78ef94a3ef7f466924fa2 (diff) | |
download | National_eIDAS_Gateway-691356756910253d77fbcdd3d58ce3051776cc5f.tar.gz National_eIDAS_Gateway-691356756910253d77fbcdd3d58ce3051776cc5f.tar.bz2 National_eIDAS_Gateway-691356756910253d77fbcdd3d58ce3051776cc5f.zip |
fix(ernp): set full person info in case of MDS update
ERnP does not support partial personData updates.
Therefore, we have to copy the latest ERnP result to all information during
an update request.
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/main/java')
-rw-r--r-- | modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java | 85 |
1 files changed, 60 insertions, 25 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java index a2f87b25..10aa020d 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java @@ -45,7 +45,6 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ErnpPersonRegisterResult; 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; @@ -59,6 +58,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.Personendaten.GeburtsbundeslandEnum; 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; @@ -266,9 +266,9 @@ public class ErnpRestClient implements IErnpClient { // select elements that have to be updated final Collection<? extends Eidas> eidasDocumentToAdd = selectEidasDocumentsToAdd(ernpPersonToKitt, eidData); - final SimpleEidasData mdsToUpdate = selectMdsInformationToUpdate(ernpPersonToKitt, eidData); + final boolean mdsValidInErnp = isMdsInErnpValid(ernpPersonToKitt, eidData); - if (eidasDocumentToAdd.isEmpty() && mdsToUpdate == null) { + if (eidasDocumentToAdd.isEmpty() && mdsValidInErnp) { log.info("Find no eIDAS document or MDS for update during: {}. Nothing todo on ERnP side", PROCESS_KITT_GENERAL); return new ErnpRegisterResult(Arrays.asList(new ErnpPersonRegisterResult(registerResult, false))); @@ -278,8 +278,7 @@ public class ErnpRestClient implements IErnpClient { PROCESS_KITT_GENERAL); // update entry based on selected update info's and results from search response - return updatePersonInErnp(ernpPersonToKitt, eidasDocumentToAdd, mdsToUpdate, eidData - .getCitizenCountryCode()); + return updatePersonInErnp(ernpPersonToKitt, eidasDocumentToAdd, mdsValidInErnp, eidData); } @@ -540,7 +539,7 @@ public class ErnpRestClient implements IErnpClient { } private ErnpRegisterResult updatePersonInErnp(Person ernpPersonToKitt, - Collection<? extends Eidas> eidasDocumentToAdd, SimpleEidasData mdsToUpdate, String citizenCountryCode) + Collection<? extends Eidas> eidasDocumentToAdd, boolean mdsValidInErnp, SimpleEidasData eidData) throws ServiceFault { // build generic request metadata final GenericRequestParams generic = buildGenericRequestParameters(); @@ -562,9 +561,9 @@ public class ErnpRestClient implements IErnpClient { } // update MDS if required - if (mdsToUpdate != null) { + if (!mdsValidInErnp) { log.debug("Find MDS to update. Injection update entries into ERnP request ... "); - ernpReq.setAendern(generateMdsChangeRequest(ernpPersonToKitt, mdsToUpdate)); + ernpReq.setAendern(generateMdsChangeRequest(ernpPersonToKitt, eidData)); } @@ -575,7 +574,7 @@ public class ErnpRestClient implements IErnpClient { log.trace("Receive response from ERnP for '{}' operation", PROCESS_KITT_IDENITIES_UPDATE); return new ErnpRegisterResult(Collections.singletonList( - mapErnpResponseToRegisterResult(ernpResp.getPerson(), citizenCountryCode))); + mapErnpResponseToRegisterResult(ernpResp.getPerson(), eidData.getCitizenCountryCode()))); } @@ -711,32 +710,68 @@ public class ErnpRestClient implements IErnpClient { return el; } - private SimpleEidasData selectMdsInformationToUpdate(Person ernpPersonToKitt, SimpleEidasData eidData) { + private boolean isMdsInErnpValid(Person ernpPersonToKitt, SimpleEidasData eidData) { final PersonendatenErgebnis person = ernpPersonToKitt.getPersonendaten(); - final SimpleEidasDataBuilder builder = SimpleEidasData.builder() - .givenName(eidData.getGivenName()) - .familyName(eidData.getFamilyName()) - .dateOfBirth(eidData.getDateOfBirth()); - - final boolean findMatch = person.getVorname().equals(eidData.getGivenName()) - && person.getFamilienname().equals(eidData.getFamilyName()) - && getTextualBirthday(person.getGeburtsdatum()).equals(eidData.getDateOfBirth()); - return findMatch ? null : builder.build(); + return person.getVorname().equalsIgnoreCase(eidData.getGivenName()) + && person.getFamilienname().equalsIgnoreCase(eidData.getFamilyName()) + && getTextualBirthday(person.getGeburtsdatum()).equalsIgnoreCase(eidData.getDateOfBirth()); } - private Aendern generateMdsChangeRequest(Person ernpPersonToKitt, SimpleEidasData mdsToUpdate) { + private Aendern generateMdsChangeRequest(Person ernpPersonToKitt, SimpleEidasData eidData) { + final PersonendatenErgebnis input = ernpPersonToKitt.getPersonendaten(); + + // copy full Person result because ERnP does not support delta updates + final Personendaten person = makeCopyOfPerson(input); + + // change MDS to eIDAS information in required + if (!input.getFamilienname().equalsIgnoreCase(eidData.getFamilyName())) { + person.setFamilienname(eidData.getFamilyName()); + + } + + if (!input.getVorname().equalsIgnoreCase(eidData.getGivenName())) { + person.setVorname(eidData.getGivenName()); + + } + + if (!getTextualBirthday(input.getGeburtsdatum()).equalsIgnoreCase(eidData.getDateOfBirth())) { + person.setGeburtsdatum(buildErnpBirthday(eidData.getDateOfBirth())); + + } + final Aendern el = new Aendern(); - final Personendaten person = new Personendaten(); - person.setEntityId(ernpPersonToKitt.getPersonendaten().getEntityId()); el.setPersonendaten(person); - person.setFamilienname(mdsToUpdate.getFamilyName()); - person.setVorname(mdsToUpdate.getGivenName()); - person.setGeburtsdatum(buildErnpBirthday(mdsToUpdate.getDateOfBirth())); return el; } + private Personendaten makeCopyOfPerson(PersonendatenErgebnis input) { + + final Personendaten person = new Personendaten(); + person.setEntityId(input.getEntityId()); + person.setFamilienname(input.getFamilienname()); + person.setGeburtsdatum(input.getGeburtsdatum()); + person.setGeburtsort(input.getGeburtsort()); + person.setGeburtsstaat(input.getGeburtsstaat()); + person.setNameVorEhe(input.getNameVorEhe()); + person.setVorname(input.getVorname()); + + if (input.getGeburtsbundesland() != null) { + person.setGeburtsbundesland( + GeburtsbundeslandEnum.fromValue(input.getGeburtsbundesland().getValue())); + + } + + if (input.getGeschlecht() != null) { + person.setGeschlecht( + Personendaten.GeschlechtEnum.fromValue(input.getGeschlecht().getValue())); + + } + return person; + + } + /** * Map an AT specific Date String 'yyyy-MM-dd' to ERnP birthday representation. * |