From 7bb4a6638ab04a19172dc303d1d6b387fa064aa0 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 1 Feb 2024 07:39:57 +0100 Subject: feat(errorhandling): update configuration-model to exclude stake-trace logging # Conflicts: # eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java --- .../gv/egiz/eaaf/core/impl/data/ErrorConfig.java | 9 ++++ .../idp/auth/AbstractAuthenticationManager.java | 2 +- .../idp/auth/services/DefaultErrorService.java | 4 ++ .../core/impl/idp/auth/services/IErrorService.java | 7 +++ .../services/ProtocolAuthenticationService.java | 50 +++++++++++++++------- .../impl/idp/auth/services/TicketErrorService.java | 5 +++ .../idp/auth/dummy/DummyDefaultErrorService.java | 4 ++ .../idp/auth/service/TicketErrorServiceTest.java | 21 +++++++++ .../src/test/resources/config/error_conf.yaml | 2 + 9 files changed, 87 insertions(+), 17 deletions(-) (limited to 'eaaf_core') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java index b9cacb1c..5f1d0976 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/data/ErrorConfig.java @@ -2,6 +2,9 @@ package at.gv.egiz.eaaf.core.impl.data; import java.util.List; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService.ActionType; import lombok.AllArgsConstructor; import lombok.Builder; @@ -44,6 +47,12 @@ public class ErrorConfig { @Builder.Default private Boolean useInternalAsExternal = false; + @Getter + @Setter + @Builder.Default + @JsonSetter(nulls = Nulls.SKIP) + private Boolean writeThrowable = true; + /** * Get type of error-handling flow. * diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java index 76bc09e6..3d0d2a3b 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/AbstractAuthenticationManager.java @@ -379,7 +379,7 @@ public abstract class AbstractAuthenticationManager implements IAuthenticationMa final Throwable taskCause = cause.getCause(); if (taskCause != null && taskCause instanceof EaafException) { final EaafException moaTaskCause = (EaafException) taskCause; - log.info(taskCause.getMessage(), taskCause); + log.info(taskCause.getMessage()); throw moaTaskCause; } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java index cd89f8a5..c9606026 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java @@ -105,6 +105,10 @@ public class DefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + @Getter + @Builder.Default + private boolean writeThrowable = true; + @Override public Map getAdditionalGuiModelElements() { return Collections.emptyMap(); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java index 45b1cfe8..d6d310a5 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java @@ -156,6 +156,13 @@ public interface IErrorService { */ Throwable getThrowable(); + /** + * Flag that indicates if stake-trace should be logged for that error. + * + * @return true in case of log stake-trace, otherwise false + */ + boolean isWriteThrowable(); + /** * Get the log-level for this internal errorId. * diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java index 6de2f94a..ef293f64 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java @@ -326,29 +326,47 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } private void logExceptionToTechnicalLog(IHandleData errorData) { - // In case of a TaskExecutionException, which is only a container for - // process-errors, - // extract internal exception + if (errorData.isWriteThrowable()) { + if (!(errorData.getThrowable() instanceof EaafException) + || LogLevel.ERROR.equals(errorData.getLogLevel())) { + log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - // Log exception - if (!(errorData.getThrowable() instanceof EaafException) - || LogLevel.ERROR.equals(errorData.getLogLevel())) { - log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { + log.warn(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { - log.warn(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { + log.info(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { - log.info(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { + log.debug(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); - } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { - log.debug(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + } else { + log.warn("Get unsupported LogLevelType: {}. Use {} as default", + errorData.getLogLevel(), LogLevel.ERROR); + log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + + } } else { - log.warn("Get unsupported LogLevelType: {}. Use {} as default", - errorData.getLogLevel(), LogLevel.ERROR); - log.error(errorData.getPreFormatedErrorMessage(), errorData.getThrowable()); + if (!(errorData.getThrowable() instanceof EaafException) + || LogLevel.ERROR.equals(errorData.getLogLevel())) { + log.error(errorData.getPreFormatedErrorMessage()); + + } else if (LogLevel.WARN.equals(errorData.getLogLevel())) { + log.warn(errorData.getPreFormatedErrorMessage()); + + } else if (LogLevel.INFO.equals(errorData.getLogLevel())) { + log.info(errorData.getPreFormatedErrorMessage()); + } else if (LogLevel.DEBUG.equals(errorData.getLogLevel())) { + log.debug(errorData.getPreFormatedErrorMessage()); + + } else { + log.warn("Get unsupported LogLevelType: {}. Use {} as default", + errorData.getLogLevel(), LogLevel.ERROR); + log.error(errorData.getPreFormatedErrorMessage()); + + } } } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java index 39262f70..08fe2159 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/TicketErrorService.java @@ -85,6 +85,7 @@ public abstract class TicketErrorService implements IErrorService { return HandleData.builder() .throwable(throwable) + .writeThrowable(errorFlowConfig.getWriteThrowable()) .internalErrorCode(internalErrorId) .actionType(errorHandlingFlow) .logLevel(LogLevel.fromString(errorFlowConfig.getLogLevel())) @@ -259,6 +260,10 @@ public abstract class TicketErrorService implements IErrorService { @Getter private LogLevel logLevel; + @Getter + @Builder.Default + private boolean writeThrowable = true; + @Getter private Map additionalGuiModelElements; diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java index ad7e9bdc..a331d382 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java @@ -107,6 +107,10 @@ public class DummyDefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + + @Getter + @Builder.Default + private boolean writeThrowable = true; @Getter private Map additionalGuiModelElements; diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java index d30f5a95..3391e109 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java @@ -34,6 +34,7 @@ import at.gv.egiz.eaaf.core.impl.idp.auth.dummy.DummyPendingRequest; import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService; import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorService.LogLevel; import ch.qos.logback.classic.spi.ILoggingEvent; +import lombok.SneakyThrows; import lombok.val; @RunWith(SpringJUnit4ClassRunner.class) @@ -67,6 +68,26 @@ public class TicketErrorServiceTest { Assert.assertEquals(external, "9199"); } + @Test + @SneakyThrows + public void checkWriteThrowableFlag() { + + DummyPendingRequest pendingReq = new DummyPendingRequest(); + pendingReq.setPendingRequestId("324"); + pendingReq.setSpEntityId(RandomStringUtils.randomAlphabetic(5)); + + Assert.assertTrue(ticketErrorService.createHandleData(new EaafException("module.binding.14"), pendingReq) + .isWriteThrowable()); + + Assert.assertTrue(ticketErrorService.createHandleData(new EaafException("internal.pendingreqid.06"), + pendingReq) + .isWriteThrowable()); + + Assert.assertFalse(ticketErrorService.createHandleData(new EaafException("module.binding.33"), pendingReq) + .isWriteThrowable()); + + } + @Test public void coverDifferentExceptions() throws EaafException { diff --git a/eaaf_core/src/test/resources/config/error_conf.yaml b/eaaf_core/src/test/resources/config/error_conf.yaml index 0e204e97..0536624e 100644 --- a/eaaf_core/src/test/resources/config/error_conf.yaml +++ b/eaaf_core/src/test/resources/config/error_conf.yaml @@ -91,6 +91,7 @@ - action: no_ticket externalCode: 1200 logLevel: info + writeThrowable: false internalCode: - module.binding.33 - module.binding.34 @@ -99,6 +100,7 @@ - action: no_ticket externalCode: 9199 logLevel: WARN + writeThrowable: true internalCode: - module.binding.14 - module.binding.25 -- cgit v1.2.3