diff options
9 files changed, 87 insertions, 17 deletions
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 4279e427..78653cf8 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 @@ -378,7 +378,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 ea045c8d..e8e22b8f 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 @@ -104,6 +104,10 @@ public class DefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + @Getter + @Builder.Default + private boolean writeThrowable = true; + @Override public Map<String, String> 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 ef04861d..657ebb4d 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 @@ -157,6 +157,13 @@ public interface IErrorService { Throwable getThrowable(); /** + * Flag that indicates if stake-trace should be logged for that error. + * + * @return <code>true</code> in case of log stake-trace, otherwise false + */ + boolean isWriteThrowable(); + + /** * Get the log-level for this internal errorId. * * @return Level to Log the error 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 84753408..b1f45801 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 @@ -328,29 +328,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 e8d6cb9a..8f32dcb0 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())) @@ -261,6 +262,10 @@ public abstract class TicketErrorService implements IErrorService { private LogLevel logLevel; @Getter + @Builder.Default + private boolean writeThrowable = true; + + @Getter private Map<String, String> additionalGuiModelElements; public String getPreFormatedErrorMessage() { 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 2c1fd087..6a15ce4d 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 @@ -106,6 +106,10 @@ public class DummyDefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + + @Getter + @Builder.Default + private boolean writeThrowable = true; @Getter private Map<String, String> 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 52149fd5..8f87383d 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 @@ -33,6 +33,7 @@ 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 jakarta.servlet.http.HttpServletRequest; +import lombok.SneakyThrows; import lombok.val; @RunWith(SpringJUnit4ClassRunner.class) @@ -67,6 +68,26 @@ public class TicketErrorServiceTest { } @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 { DummyPendingRequest pendingReq = new DummyPendingRequest(); 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 |