diff options
author | Thomas <> | 2022-10-21 11:11:36 +0200 |
---|---|---|
committer | Thomas <> | 2022-10-21 11:11:36 +0200 |
commit | 55ab5856a90b065b2a645a62112b380f06cf751c (patch) | |
tree | 4c0be982a90e655a816464d0b51d272bf94c6bce /modules | |
parent | 8c09e7fbee0f8e1bc5e1c6e89e2aaf6fa4bec7a5 (diff) | |
download | National_eIDAS_Gateway-55ab5856a90b065b2a645a62112b380f06cf751c.tar.gz National_eIDAS_Gateway-55ab5856a90b065b2a645a62112b380f06cf751c.tar.bz2 National_eIDAS_Gateway-55ab5856a90b065b2a645a62112b380f06cf751c.zip |
feat(matching): distiguish between create ERnP entry by automated process or by user decision
Diffstat (limited to 'modules')
6 files changed, 87 insertions, 7 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java index faf38b64..0d0d11f8 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java @@ -336,10 +336,20 @@ public class Constants { /** * {@link at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.CreateNewErnpEntryTask}. + * + * <p>In case of an automated decision to create ERnP entry</p> */ public static final String TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK = "TASK_CreateNewErnpEntryTask"; /** + * {@link at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.CreateNewErnpEntryTask}. + * + * <p>In case of an user decision to create ERnP entry</p> + */ + public static final String TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK = + "TASK_CreateNewErnpEntryByUserTask"; + + /** * {@link at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.GenerateOtherLoginMethodGuiTask}. */ public static final String TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK = diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java index 563a66ba..5926adc6 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/CreateNewErnpEntryTask.java @@ -23,6 +23,8 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks; +import java.io.Serializable; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -93,7 +95,7 @@ public class CreateNewErnpEntryTask extends AbstractAuthServletTask { // finish matching process, because new user-entry uniquly matches log.info("User successfully registerred into ERnP and matching tasks are finished "); - MatchingTaskUtils.setMatchingState(pendingReq, MatchingStates.BY_NEW_ERNP_ENTRY); + MatchingTaskUtils.setMatchingState(pendingReq, selectMatchingStateByContextInfos(executionContext)); MatchingTaskUtils.storeFinalMatchingResult(pendingReq, MatchedPersonResult.generateFormMatchingResult( resp.getPersonResult().get(0), simpleEidasData.getCitizenCountryCode())); @@ -104,4 +106,11 @@ public class CreateNewErnpEntryTask extends AbstractAuthServletTask { } } + private MatchingStates selectMatchingStateByContextInfos(ExecutionContext executionContext) { + Serializable flag = executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK); + return flag != null && (boolean) flag + ? MatchingStates.BY_USER_TO_NEW_ERNP_ENTRY : MatchingStates.BY_NEW_ERNP_ENTRY; + + } + } diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java index 5b966ffe..fb4e6e7b 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java @@ -73,7 +73,8 @@ public class ReceiveOtherLoginMethodGuiResponseTask extends AbstractLocaleAuthSe Constants.TRANSITION_TO_GENERATE_EIDAS_LOGIN, Constants.TRANSITION_TO_GENERATE_MOBILE_PHONE_SIGNATURE_REQUEST_TASK, Constants.TRANSITION_TO_GENERATE_GUI_QUERY_AUSTRIAN_RESIDENCE_TASK, - Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); + Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, + Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK); @Override public void executeWithLocale(ExecutionContext executionContext, HttpServletRequest request, @@ -146,7 +147,7 @@ public class ReceiveOtherLoginMethodGuiResponseTask extends AbstractLocaleAuthSe case ADD_ME_AS_NEW: log.info("User selects insert-into-ERnP option. Starting ERnP operation and complete prozess ... "); - executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true); + executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK, true); executionContext.put(Constants.TRANSITION_TO_REQUESTING_NEW_ERNP_ENTRY_TASK, false); return; diff --git a/modules/authmodule-eIDAS-v2/src/main/resources/eIDAS.Authentication.process.xml b/modules/authmodule-eIDAS-v2/src/main/resources/eIDAS.Authentication.process.xml index e57f9ca6..3a37a82b 100644 --- a/modules/authmodule-eIDAS-v2/src/main/resources/eIDAS.Authentication.process.xml +++ b/modules/authmodule-eIDAS-v2/src/main/resources/eIDAS.Authentication.process.xml @@ -47,7 +47,7 @@ from="receiveOtherLoginMethodGuiResponseTask" to="generateAustrianResidenceGuiTask" /> <pd:Transition conditionExpression="ctx['TASK_RequestingNewErnpEntryTask']" from="receiveOtherLoginMethodGuiResponseTask" to="generateOtherLoginMethodGuiTask" /> - <pd:Transition conditionExpression="ctx['TASK_CreateNewErnpEntryTask']" + <pd:Transition conditionExpression="ctx['TASK_CreateNewErnpEntryByUserTask']" from="receiveOtherLoginMethodGuiResponseTask" to="createNewErnpEntryTask" /> <!-- alternative eIDAS authentication --> diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java index 6298e250..c3beff33 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java @@ -27,6 +27,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import at.asitplus.eidas.specific.core.MsEidasNodeConstants; +import at.asitplus.eidas.specific.core.MsEidasNodeConstants.MatchingStates; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient.ErnpRegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ErnpPersonRegisterResult; @@ -55,7 +58,7 @@ public class CreateNewErnpEntryTaskTest { @Mock ErnpRestClient ernpClient; - final ExecutionContext executionContext = new ExecutionContextImpl(); + private ExecutionContext executionContext; private TestRequestImpl pendingReq; /** @@ -70,6 +73,8 @@ public class CreateNewErnpEntryTaskTest { RequestContextHolder.resetRequestAttributes(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + executionContext = new ExecutionContextImpl(); + pendingReq = new TestRequestImpl(); pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); @@ -145,10 +150,64 @@ public class CreateNewErnpEntryTaskTest { assertEquals("givenyname", input.getGivenName(), result.getGivenName()); assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth()); assertEquals("bpk", bpk, result.getBpk()); - assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode()); + assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode()); + assertEquals("matching state", MatchingStates.BY_NEW_ERNP_ENTRY, + pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); } + @Test + @SneakyThrows + public void insertErnpByAutoselectionSuccess() { + String bpk = RandomStringUtils.randomAlphabetic(5); + SimpleEidasData input = buildInputData(); + Mockito.when(ernpClient.add(input)) + .thenReturn(ernpRegisterResult(Arrays.asList(buildErnpResultEntry(input, bpk)))); + + executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true); + + // perform test + task.execute(pendingReq, executionContext); + + // validate state + MatchedPersonResult result = MatchingTaskUtils.getFinalMatchingResult(pendingReq); + assertNotNull("no matching result", result); + assertEquals("familyname", input.getFamilyName(), result.getFamilyName()); + assertEquals("givenyname", input.getGivenName(), result.getGivenName()); + assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth()); + assertEquals("bpk", bpk, result.getBpk()); + assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode()); + assertEquals("matching state", MatchingStates.BY_NEW_ERNP_ENTRY, + pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); + + } + + @Test + @SneakyThrows + public void insertErnpByUserSuccess() { + String bpk = RandomStringUtils.randomAlphabetic(5); + SimpleEidasData input = buildInputData(); + Mockito.when(ernpClient.add(input)) + .thenReturn(ernpRegisterResult(Arrays.asList(buildErnpResultEntry(input, bpk)))); + + executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK, true); + + // perform test + task.execute(pendingReq, executionContext); + + // validate state + MatchedPersonResult result = MatchingTaskUtils.getFinalMatchingResult(pendingReq); + assertNotNull("no matching result", result); + assertEquals("familyname", input.getFamilyName(), result.getFamilyName()); + assertEquals("givenyname", input.getGivenName(), result.getGivenName()); + assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth()); + assertEquals("bpk", bpk, result.getBpk()); + assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode()); + assertEquals("matching state", MatchingStates.BY_USER_TO_NEW_ERNP_ENTRY, + pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); + + } + @NotNull private ErnpRegisterResult ernpRegisterResult(List<RegisterResult> registerResult) { diff --git a/modules/core_common_lib/src/main/java/at/asitplus/eidas/specific/core/MsEidasNodeConstants.java b/modules/core_common_lib/src/main/java/at/asitplus/eidas/specific/core/MsEidasNodeConstants.java index 4304ddd5..c48697e0 100644 --- a/modules/core_common_lib/src/main/java/at/asitplus/eidas/specific/core/MsEidasNodeConstants.java +++ b/modules/core_common_lib/src/main/java/at/asitplus/eidas/specific/core/MsEidasNodeConstants.java @@ -237,7 +237,8 @@ public class MsEidasNodeConstants { BY_ID_AUSTRIA, BY_EIDAS, BY_ADDRESS, - BY_NEW_ERNP_ENTRY } + BY_NEW_ERNP_ENTRY, + BY_USER_TO_NEW_ERNP_ENTRY } private MsEidasNodeConstants() { //hidden Constructor for class with static values only. |