From d39f2b7b7b4e2fea2a5402c63c10d3ce83097129 Mon Sep 17 00:00:00 2001
From: Thomas <>
Date: Thu, 23 Mar 2023 17:24:53 +0100
Subject: chore(core): update statistic logger as requested by the BM.I
---
ms_specific_proxyservice/pom.xml | 4 +
.../proxy/logger/AdvancedStatisicLogger.java | 176 --------------------
.../proxy/logger/AdvancedStatisticLogger.java | 182 +++++++++++++++++++++
.../proxy/logger/MultipleStatisticLogger.java | 4 +-
4 files changed, 188 insertions(+), 178 deletions(-)
delete mode 100644 ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisicLogger.java
create mode 100644 ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisticLogger.java
(limited to 'ms_specific_proxyservice')
diff --git a/ms_specific_proxyservice/pom.xml b/ms_specific_proxyservice/pom.xml
index 78b425fe..4d388b2d 100644
--- a/ms_specific_proxyservice/pom.xml
+++ b/ms_specific_proxyservice/pom.xml
@@ -68,6 +68,10 @@
org.springframework
spring-context
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-properties
+
org.slf4j
slf4j-api
diff --git a/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisicLogger.java b/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisicLogger.java
deleted file mode 100644
index cf55281d..00000000
--- a/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisicLogger.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package at.asitplus.eidas.specific.proxy.logger;
-
-import java.time.LocalDateTime;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
-import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
-
-import at.asitplus.eidas.specific.modules.msproxyservice.MsProxyServiceConstants;
-import at.gv.egiz.eaaf.core.api.IRequest;
-import at.gv.egiz.eaaf.core.api.IStatusMessenger;
-import at.gv.egiz.eaaf.core.api.data.PvpAttributeDefinitions;
-import at.gv.egiz.eaaf.core.api.idp.IAuthData;
-import at.gv.egiz.eaaf.core.api.idp.IEidAuthData;
-import at.gv.egiz.eaaf.core.api.logging.IStatisticLogger;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Extended statistic logger that use a JSON based data model.
- *
- * @author tlenz
- *
- */
-@Slf4j
-public class AdvancedStatisicLogger implements IStatisticLogger {
-
- private static final String DATEFORMATER = "yyyy.MM.dd-HH:mm:ss";
- private static final String DEFAULT_NO_IDP_ID = "no idpId available";
-
- private static final ObjectMapper mapper = new ObjectMapper();
-
- private final IStatusMessenger messageService;
-
- /**
- * Build a JSON based statistic logger that uses error messages from a specific source.
- *
- * @param source i18n message source
- */
- public AdvancedStatisicLogger(IStatusMessenger source) {
- this.messageService = source;
-
- }
-
- @Override
- public void logSuccessOperation(IRequest protocolRequest, IAuthData authData, boolean isSsoSession) {
- final StatisticLogEntry entry = buildCoreEntry(protocolRequest);
- entry.setSuccess(SuccessEntry.builder()
- .spSector(protocolRequest.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier())
- .spCountry(protocolRequest.getServiceProviderConfiguration().getConfigurationValue(
- MsProxyServiceConstants.CONIG_PROPS_CONNECTOR_COUNTRYCODE))
- .withMandates(selectMandateProcessType(authData))
- .build());
- writeEntryToLog(entry);
-
- }
-
- @Override
- public void logErrorOperation(Throwable throwable) {
- log.trace("Advanced statistic logger only logs on SP level");
-
- }
-
- @Override
- public void logErrorOperation(Throwable throwable, IRequest errorRequest) {
- final StatisticLogEntry entry = buildCoreEntry(errorRequest);
- entry.setError(new ErrorEntry(messageService.getResponseErrorCode(throwable), throwable.getMessage()));
- writeEntryToLog(entry);
-
- }
-
- @Override
- public void internalTesting() throws Exception {
- log.trace("Not implemented for a File-based logger");
-
- }
-
- private StatisticLogEntry buildCoreEntry(IRequest pendingRequest) {
- return new StatisticLogEntry(
- LocalDateTime.now(),
- pendingRequest.getUniqueTransactionIdentifier(),
- pendingRequest.getServiceProviderConfiguration() != null
- && pendingRequest.getServiceProviderConfiguration().getUniqueIdentifier() != null
- ? pendingRequest.getServiceProviderConfiguration().getUniqueIdentifier() : DEFAULT_NO_IDP_ID);
-
- }
-
- private MandateProcess selectMandateProcessType(IAuthData authData) {
- if (authData instanceof IEidAuthData && ((IEidAuthData)authData).isUseMandate()) {
- return authData.getGenericData(PvpAttributeDefinitions.MANDATE_LEG_PER_SOURCE_PIN_NAME, String.class) != null
- ? MandateProcess.FOR_LEGAL_PERSON : MandateProcess.FOR_NATURAL_PERSON;
-
- } else {
- return MandateProcess.NONE;
-
- }
- }
-
- private void writeEntryToLog(StatisticLogEntry entry) {
- try {
- log.info(mapper.writeValueAsString(entry));
-
- } catch (final JsonProcessingException e) {
- log.error("Can NOT generate statistic entry for logging", e);
-
- }
- }
-
- public enum MandateProcess { NONE, FOR_NATURAL_PERSON, FOR_LEGAL_PERSON }
-
- @Getter
- @Setter
- @RequiredArgsConstructor
- @JsonInclude(Include.NON_NULL)
- private static class StatisticLogEntry {
-
- @JsonSerialize(using = LocalDateTimeSerializer.class)
- @JsonDeserialize(using = LocalDateTimeDeserializer.class)
- @JsonFormat(pattern = DATEFORMATER)
- @JsonProperty("timestamp")
- private final LocalDateTime timestamp;
-
- @JsonProperty("txId")
- private final String transactionId;
-
- @JsonProperty("entityId")
- private final String idpEntityId;
-
- @JsonProperty("success")
- private SuccessEntry success;
-
- @JsonProperty("error")
- private ErrorEntry error;
-
- }
-
- @Getter
- @Setter
- @Builder
- @JsonInclude(Include.NON_NULL)
- private static class SuccessEntry {
-
- @JsonProperty("spSector")
- private final String spSector;
-
- @JsonProperty("spCountry")
- private final String spCountry;
-
- @JsonProperty("withMandates")
- private final MandateProcess withMandates;
-
- }
-
- @Getter
- @Setter
- @RequiredArgsConstructor
- private static class ErrorEntry {
-
- @JsonProperty("code")
- private final String errorCode;
-
- @JsonProperty("msg")
- private final String errorMessage;
-
- }
-}
diff --git a/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisticLogger.java b/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisticLogger.java
new file mode 100644
index 00000000..55833b8b
--- /dev/null
+++ b/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/AdvancedStatisticLogger.java
@@ -0,0 +1,182 @@
+package at.asitplus.eidas.specific.proxy.logger;
+
+import java.io.IOException;
+import java.time.LocalDateTime;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+
+import at.asitplus.eidas.specific.modules.msproxyservice.MsProxyServiceConstants;
+import at.gv.egiz.eaaf.core.api.IRequest;
+import at.gv.egiz.eaaf.core.api.IStatusMessenger;
+import at.gv.egiz.eaaf.core.api.data.PvpAttributeDefinitions;
+import at.gv.egiz.eaaf.core.api.idp.IAuthData;
+import at.gv.egiz.eaaf.core.api.idp.IEidAuthData;
+import at.gv.egiz.eaaf.core.api.logging.IStatisticLogger;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Extended statistic logger that use a JSON based data model.
+ *
+ * @author tlenz
+ *
+ */
+@Slf4j
+public class AdvancedStatisticLogger implements IStatisticLogger {
+
+ private static final String DATEFORMATER = "yyyy.MM.dd-HH:mm:ss,SSS";
+ private static final String DEFAULT_NO_IDP_ID = "no idpId available";
+
+ private static final ObjectMapper mapper = new ObjectMapper();
+ private static final JavaPropsMapper propsMapper = new JavaPropsMapper();
+
+ private final IStatusMessenger messageService;
+
+ /**
+ * Build a JSON based statistic logger that uses error messages from a specific source.
+ *
+ * @param source i18n message source
+ */
+ public AdvancedStatisticLogger(IStatusMessenger source) {
+ this.messageService = source;
+
+ }
+
+ @Override
+ public void logSuccessOperation(IRequest protocolRequest, IAuthData authData, boolean isSsoSession) {
+ final StatisticLogEntry entry = buildCoreEntry(protocolRequest);
+ entry.setSuccess(SuccessEntry.builder()
+ .spSector(protocolRequest.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier())
+ .spCountry(protocolRequest.getServiceProviderConfiguration().getConfigurationValue(
+ MsProxyServiceConstants.CONIG_PROPS_CONNECTOR_COUNTRYCODE))
+ .citizenCountryCode("AT")
+ .withMandates(selectMandateProcessType(authData))
+ .build());
+ writeEntryToLog(entry);
+
+ }
+
+ @Override
+ public void logErrorOperation(Throwable throwable) {
+ log.trace("Advanced statistic logger only logs on SP level");
+
+ }
+
+ @Override
+ public void logErrorOperation(Throwable throwable, IRequest errorRequest) {
+ final StatisticLogEntry entry = buildCoreEntry(errorRequest);
+ entry.setError(new ErrorEntry(messageService.getResponseErrorCode(throwable), throwable.getMessage()));
+ writeEntryToLog(entry);
+
+ }
+
+ @Override
+ public void internalTesting() throws Exception {
+ log.trace("Not implemented for a File-based logger");
+
+ }
+
+ private StatisticLogEntry buildCoreEntry(IRequest pendingRequest) {
+ return new StatisticLogEntry(
+ LocalDateTime.now(),
+ pendingRequest.getUniqueTransactionIdentifier(),
+ pendingRequest.getServiceProviderConfiguration() != null
+ && pendingRequest.getServiceProviderConfiguration().getUniqueIdentifier() != null
+ ? pendingRequest.getServiceProviderConfiguration().getUniqueIdentifier() : DEFAULT_NO_IDP_ID);
+
+ }
+
+ private MandateProcess selectMandateProcessType(IAuthData authData) {
+ if (authData instanceof IEidAuthData && ((IEidAuthData)authData).isUseMandate()) {
+ return authData.getGenericData(PvpAttributeDefinitions.MANDATE_LEG_PER_SOURCE_PIN_NAME, String.class) != null
+ ? MandateProcess.FOR_LEGAL_PERSON : MandateProcess.FOR_NATURAL_PERSON;
+
+ } else {
+ return MandateProcess.NONE;
+
+ }
+ }
+
+ private void writeEntryToLog(StatisticLogEntry entry) {
+ try {
+ log.info(mapper.writeValueAsString(propsMapper.writeValueAsProperties(entry)));
+
+ } catch (final IOException e) {
+ log.error("Can NOT generate statistic entry for logging", e);
+
+ }
+ }
+
+ public enum MandateProcess { NONE, FOR_NATURAL_PERSON, FOR_LEGAL_PERSON }
+
+ @Getter
+ @Setter
+ @RequiredArgsConstructor
+ @JsonInclude(Include.NON_NULL)
+ private static class StatisticLogEntry {
+
+ @JsonSerialize(using = LocalDateTimeSerializer.class)
+ @JsonDeserialize(using = LocalDateTimeDeserializer.class)
+ @JsonFormat(pattern = DATEFORMATER)
+ @JsonProperty("timestamp")
+ private final LocalDateTime timestamp;
+
+ @JsonProperty("txId")
+ private final String transactionId;
+
+ @JsonProperty("entityId")
+ private final String idpEntityId;
+
+ @JsonProperty("result")
+ private SuccessEntry success;
+
+ @JsonProperty("error")
+ private ErrorEntry error;
+
+ }
+
+ @Getter
+ @Setter
+ @Builder
+ @JsonInclude(Include.NON_NULL)
+ private static class SuccessEntry {
+
+ @JsonProperty("spSector")
+ private final String spSector;
+
+ @JsonProperty("spCountry")
+ private final String spCountry;
+
+ @JsonProperty("citizenCountryCode")
+ private final String citizenCountryCode;
+
+ @JsonProperty("withMandates")
+ private final MandateProcess withMandates;
+
+ }
+
+ @Getter
+ @Setter
+ @RequiredArgsConstructor
+ private static class ErrorEntry {
+
+ @JsonProperty("code")
+ private final String errorCode;
+
+ @JsonProperty("msg")
+ private final String errorMessage;
+
+ }
+}
diff --git a/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/MultipleStatisticLogger.java b/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/MultipleStatisticLogger.java
index bd771fb2..ccd81a27 100644
--- a/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/MultipleStatisticLogger.java
+++ b/ms_specific_proxyservice/src/main/java/at/asitplus/eidas/specific/proxy/logger/MultipleStatisticLogger.java
@@ -24,7 +24,7 @@ public class MultipleStatisticLogger implements IStatisticLogger {
private final Set internalLoggers;
/**
- * Build a statistic logger that logs into {@link StatisticLogger} and {@link AdvancedStatisicLogger}.
+ * Build a statistic logger that logs into {@link StatisticLogger} and {@link AdvancedStatisticLogger}.
*
* @param messageService i18n message-source implementation.
*/
@@ -32,7 +32,7 @@ public class MultipleStatisticLogger implements IStatisticLogger {
internalLoggers = Collections.unmodifiableSet(
Sets.newHashSet(
new StatisticLogger(),
- new AdvancedStatisicLogger(messageService)));
+ new AdvancedStatisticLogger(messageService)));
}
--
cgit v1.2.3