aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorThomas <>2022-08-22 17:10:28 +0200
committerThomas <>2022-08-22 17:10:28 +0200
commitc8dfbc7f0b55a4f8c5238452055e5087fe46d675 (patch)
tree00f78021478af4a96b0e41f61eaf0c6e4a7781f9 /modules
parent28d59b19a4bc60ce4662e01a3c2ae18d38e675e6 (diff)
downloadNational_eIDAS_Gateway-c8dfbc7f0b55a4f8c5238452055e5087fe46d675.tar.gz
National_eIDAS_Gateway-c8dfbc7f0b55a4f8c5238452055e5087fe46d675.tar.bz2
National_eIDAS_Gateway-c8dfbc7f0b55a4f8c5238452055e5087fe46d675.zip
feat(core): add default error-handler to show custom error-page on any error
Diffstat (limited to 'modules')
-rw-r--r--modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/controller/DefaultErrorController.java75
-rw-r--r--modules/core_common_webapp/src/main/resources/specific_eIDAS_core.beans.xml3
2 files changed, 78 insertions, 0 deletions
diff --git a/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/controller/DefaultErrorController.java b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/controller/DefaultErrorController.java
new file mode 100644
index 00000000..a9944674
--- /dev/null
+++ b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/controller/DefaultErrorController.java
@@ -0,0 +1,75 @@
+package at.asitplus.eidas.specific.core.controller;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import at.gv.egiz.eaaf.core.api.data.EaafConstants;
+import at.gv.egiz.eaaf.core.api.idp.auth.services.IProtocolAuthenticationService;
+import at.gv.egiz.eaaf.core.exceptions.EaafException;
+import at.gv.egiz.eaaf.core.impl.idp.controller.AbstractController;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Default error handler for any request that is not part of MS-eIDAS-Node.
+ *
+ * @author tlenz
+ *
+ */
+@Slf4j
+@Controller
+public class DefaultErrorController extends AbstractController implements ErrorController {
+
+ private static final String INTERNAL_97 = "internal.97";
+ private static final String INTERNAL_96 = "internal.96";
+
+ @Autowired(required = true)
+ protected IProtocolAuthenticationService protAuthService;
+
+ /**
+ * generic error-handler for any error that is not handled otherwise.
+ *
+ * @param req Current HTTP request
+ * @param resp Current HTTP response
+ * @throws IOException In case of an internal error
+ */
+ @RequestMapping(EaafConstants.ENDPOINT_PREFIX_PUBLIC + "/error")
+ public void handleGenericErrors(final HttpServletRequest req, final HttpServletResponse resp)
+ throws IOException {
+ final Object status = req.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
+
+ if (status != null) {
+ final Integer statusCode = Integer.valueOf(status.toString());
+ if (statusCode == HttpStatus.NOT_FOUND.value()) {
+ forwardToCentralErrorHandling(new EaafException(INTERNAL_97), req, resp);
+ return;
+
+ }
+ }
+
+ forwardToCentralErrorHandling(new EaafException(INTERNAL_96), req, resp);
+
+ }
+
+ private void forwardToCentralErrorHandling(Throwable e, HttpServletRequest req, HttpServletResponse resp)
+ throws IOException {
+ try {
+ protAuthService.handleErrorNoRedirect(e, req, resp, false);
+
+ } catch (final EaafException e1) {
+ log.warn("ErrorHandling failed with error: ", e.getMessage(), e);
+ log.warn("Can NOT handle an 'EAAFException'. Forwarding to generic error ... ", e);
+ ioExceptionHandler(resp, e);
+
+ }
+ }
+
+}
diff --git a/modules/core_common_webapp/src/main/resources/specific_eIDAS_core.beans.xml b/modules/core_common_webapp/src/main/resources/specific_eIDAS_core.beans.xml
index af3594a5..04694ef1 100644
--- a/modules/core_common_webapp/src/main/resources/specific_eIDAS_core.beans.xml
+++ b/modules/core_common_webapp/src/main/resources/specific_eIDAS_core.beans.xml
@@ -28,6 +28,9 @@
<property name="guiBuilder" ref="mvcGUIBuilderImpl" />
</bean>
+ <bean id="genericErrorHandler"
+ class="at.asitplus.eidas.specific.core.controller.DefaultErrorController" />
+
<bean id="securePendingRequestIdGeneration"
class="at.gv.egiz.eaaf.core.impl.utils.SecurePendingRequestIdGenerationStrategy" />