aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth
diff options
context:
space:
mode:
authorChristian Kollmann <christian.kollmann@a-sit.at>2021-02-25 11:32:57 +0100
committerChristian Kollmann <christian.kollmann@a-sit.at>2021-02-25 13:27:18 +0100
commit2c49670334049a065d86defc8524f2e5eae6ca78 (patch)
treedbf4b965e6e935eb0bb6fe4030b3440ce811a664 /eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth
parent8c13c21799beed76eea848504677eb935026397c (diff)
downloadNational_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.tar.gz
National_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.tar.bz2
National_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.zip
Refactor and test ReceiveOtherLoginMethodGuiResponse
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/GenerateOtherLoginMethodGuiTask.java5
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java71
2 files changed, 40 insertions, 36 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/GenerateOtherLoginMethodGuiTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/GenerateOtherLoginMethodGuiTask.java
index 0236b9c2..56aaa2db 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/GenerateOtherLoginMethodGuiTask.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/GenerateOtherLoginMethodGuiTask.java
@@ -40,8 +40,11 @@ import javax.servlet.http.HttpServletResponse;
/**
* Task that provides GUI for user to select an alternative login method.
- * This page is shown when the matching of the eIDAS data to ZMR/ERnP data is ambiguous
+ * This page is shown when the matching of the eIDAS data to ZMR/ERnP data is ambiguous.
+ * This corresponds to Steps 10, 14, 16 in the eIDAS Matching Concept.
+ * The response is handled in {@link ReceiveOtherLoginMethodGuiResponseTask}
*
+ * @author amarsalek
* @author ckollmann
*/
@Slf4j
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java
index d8b80689..12eb7a83 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveOtherLoginMethodGuiResponseTask.java
@@ -26,13 +26,11 @@ 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.SelectedLoginMethod;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.InvalidUserInputException;
-import at.gv.egiz.eaaf.core.api.data.EaafConstants;
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.modules.AbstractAuthServletTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
@@ -41,7 +39,9 @@ import java.util.Enumeration;
/**
* Handles user's selection from {@link GenerateOtherLoginMethodGuiTask}.
+ * This corresponds to Steps 10, 14, 16 in the eIDAS Matching Concept.
*
+ * @author amarsalek
* @author ckollmann
*/
@Slf4j
@@ -51,44 +51,45 @@ public class ReceiveOtherLoginMethodGuiResponseTask extends AbstractAuthServletT
@Override
public void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response)
throws TaskExecutionException {
- int found = 0;
try {
- // set parameter execution context
- final Enumeration<String> reqParamNames = request.getParameterNames();
- while (reqParamNames.hasMoreElements()) {
- final String paramName = reqParamNames.nextElement();
- if (StringUtils.isNotEmpty(paramName)
- && !EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID.equalsIgnoreCase(paramName)
- && Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER.equalsIgnoreCase(paramName)) {
- String value = StringEscapeUtils.escapeHtml(request.getParameter(paramName));
- SelectedLoginMethod selection = SelectedLoginMethod.valueOf(value);
- executionContext.put(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, selection);
- switch (selection) {
- case EIDAS_LOGIN:
- executionContext.put(Constants.TRANSITION_TO_GENERATE_EIDAS_LOGIN, true);
- found++;
- break;
- case MOBILE_PHONE_SIGNATURE_LOGIN:
- executionContext.put(Constants.TRANSITION_TO_GENERATE_MOBILE_PHONE_SIGNATURE_REQUEST_TASK, true);
- found++;
- break;
- case NO_OTHER_LOGIN:
- executionContext.put(Constants.TRANSITION_TO_GENERATE_GUI_QUERY_AUSTRIAN_RESIDENCE_TASK, true);
- found++;
- break;
- default:
- throw new InvalidUserInputException();
- }
- }
- }
+ SelectedLoginMethod selection = SelectedLoginMethod.valueOf(extractUserSelection(request));
+ executionContext.put(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, selection);
+ transitionToNextTask(executionContext, selection);
+ } catch (final IllegalArgumentException e) {
+ log.error("Parsing selected login method FAILED.", e);
+ throw new TaskExecutionException(pendingReq, "Parsing selected login method FAILED.",
+ new InvalidUserInputException());
} catch (final Exception e) {
log.error("Parsing selected login method FAILED.", e);
throw new TaskExecutionException(pendingReq, "Parsing selected login method FAILED.", e);
}
- if (found != 1) {
- log.error("Parsing selected login method FAILED.");
- throw new TaskExecutionException(pendingReq, "Parsing selected login method FAILED.",
- new InvalidUserInputException());
+ }
+
+ private String extractUserSelection(HttpServletRequest request) throws InvalidUserInputException {
+ Enumeration<String> paramNames = request.getParameterNames();
+ while (paramNames.hasMoreElements()) {
+ String paramName = paramNames.nextElement();
+ if (Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER.equalsIgnoreCase(paramName)) {
+ return StringEscapeUtils.escapeHtml(request.getParameter(paramName));
+ }
+ }
+ throw new InvalidUserInputException();
+ }
+
+ private void transitionToNextTask(ExecutionContext executionContext, SelectedLoginMethod selection)
+ throws InvalidUserInputException {
+ switch (selection) {
+ case EIDAS_LOGIN:
+ executionContext.put(Constants.TRANSITION_TO_GENERATE_EIDAS_LOGIN, true);
+ return;
+ case MOBILE_PHONE_SIGNATURE_LOGIN:
+ executionContext.put(Constants.TRANSITION_TO_GENERATE_MOBILE_PHONE_SIGNATURE_REQUEST_TASK, true);
+ return;
+ case NO_OTHER_LOGIN:
+ executionContext.put(Constants.TRANSITION_TO_GENERATE_GUI_QUERY_AUSTRIAN_RESIDENCE_TASK, true);
+ return;
+ default:
+ throw new InvalidUserInputException();
}
}