diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-11-06 08:16:08 +0200 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-11-06 09:20:53 +0000 |
commit | 06e518055d9758ee3ecc2e40efe13c7a5d982a2a (patch) | |
tree | 6eda3ee37920da456a42643fc001a7d752ff6e69 /vid-app-common/src/main | |
parent | b84d6332c492206cecf11d54a884c8a299ef1690 (diff) |
print user-id in partner name record of audit log
Issue-ID: VID-253
Also add more verifications for audit log format
Change-Id: I00976a63fd1a795a972c13ad975d6a71248e5c8b
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java | 4 | ||||
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java | 33 |
2 files changed, 35 insertions, 2 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java index 91fb94231..096dba39f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -66,6 +66,7 @@ import org.onap.vid.services.PombaService; import org.onap.vid.services.PombaServiceImpl; import org.onap.vid.utils.JoshworksJacksonObjectMapper; import org.onap.vid.utils.Logging; +import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -222,6 +223,7 @@ public class WebConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new VidLoggingInterceptor()); + registry.addInterceptor(new VidLoggingInterceptor( + new ControllersUtils(new SystemPropertiesWrapper()))); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java index abc7048da..fe8b470ec 100644 --- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java +++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggingInterceptor.java @@ -24,8 +24,12 @@ import java.net.InetAddress; import java.net.UnknownHostException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.StringUtils; +import org.onap.logging.filter.base.MDCSetup; +import org.onap.logging.filter.base.SimpleMap; import org.onap.logging.filter.spring.LoggingInterceptor; import org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs; +import org.onap.vid.controller.ControllersUtils; import org.slf4j.MDC; import org.springframework.web.servlet.ModelAndView; @@ -34,6 +38,11 @@ public class VidLoggingInterceptor extends LoggingInterceptor { static final String INBOUND_INVO_ID = "InboundInvoId"; private static final String canonicalHostName = getCanonicalName(); + private final ControllersUtils controllersUtils; + + public VidLoggingInterceptor(ControllersUtils controllersUtils) { + this.controllersUtils = controllersUtils; + } private static String getCanonicalName() { try { @@ -45,9 +54,30 @@ public class VidLoggingInterceptor extends LoggingInterceptor { } @Override - protected void additionalPreHandling(HttpServletRequest request) { + protected void additionalPreHandling(HttpServletRequest request) { super.additionalPreHandling(request); storeInboundInvocationId(); + fillPartnerNameWithUserId(request); + } + + void fillPartnerNameWithUserId(HttpServletRequest request) { + String userId = controllersUtils.extractUserId(request); + if (StringUtils.isNotEmpty(userId)) { + MDC.put(MDCs.PARTNER_NAME, userId); + } + } + + @Override + //this method override fix bug in logging library + //that may throw some exceptions, e.g. StringIndexOutOfBoundsException + protected String getBasicAuthUserName(SimpleMap headers) { + try { + return super.getBasicAuthUserName(headers); + } catch (Exception e) { + MDCSetup.logger.error("failed to getBasicAuthUserName", e); + } + + return null; } /* @@ -61,6 +91,7 @@ public class VidLoggingInterceptor extends LoggingInterceptor { public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { restoreInvocationId(); fixServerFQDN(); + fillPartnerNameWithUserId(request); super.postHandle(request, response, handler, modelAndView); } |