summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/AuditLog.java32
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAdvice.java234
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAspect.java88
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/MetricsLog.java32
4 files changed, 0 insertions, 386 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/AuditLog.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/AuditLog.java
deleted file mode 100644
index 6cb661b1..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/AuditLog.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-
- * ================================================================================
- * eCOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
-package org.openecomp.portalsdk.core.logging.aspect;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface AuditLog {
- String value() default "";
-} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAdvice.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
deleted file mode 100644
index da4e2aff..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*-
- * ================================================================================
- * eCOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
-package org.openecomp.portalsdk.core.logging.aspect;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.openecomp.portalsdk.core.logging.format.AuditLogFormatter;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.portalsdk.core.service.AppService;
-import org.openecomp.portalsdk.core.util.SystemProperties;
-import org.openecomp.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
-import org.slf4j.MDC;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.att.eelf.configuration.Configuration;
-
-@org.springframework.context.annotation.Configuration
-public class EELFLoggerAdvice {
-
- @Autowired
- AppService appService;
-
- EELFLoggerDelegate adviceLogger = EELFLoggerDelegate.getLogger(EELFLoggerAdvice.class);
-
- // DateTime Format according to the ECOMP Application Logging Guidelines.
- private static final SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-
- /**
- * Gets the current date and time in expected ECOMP log format.
- *
- * @return Current date and time
- */
- public static String getCurrentDateTimeUTC() {
- String currentDateTime = ecompLogDateFormat.format(new Date());
- return currentDateTime;
- }
-
- /**
- *
- * @param securityEventType
- * @param args
- * @param passOnArgs
- * @return One-element array containing an empty String object.
- */
- public Object[] before(SecurityEventTypeEnum securityEventType, Object[] args, Object[] passOnArgs) {
- try {
- String className = "";
- if (passOnArgs[0] != null) {
- className = passOnArgs[0].toString();
- }
-
- String methodName = "";
- if (passOnArgs[1] != null) {
- methodName = passOnArgs[1].toString();
- }
-
- String appName = appService.getDefaultAppName();
- if (appName == null || appName == "") {
- appName = SystemProperties.SDK_NAME;
- }
-
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
-
- // Initialize Request defaults only for controller methods.
- MDC.put(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
- MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE");
- MDC.put(SystemProperties.TARGET_SERVICE_NAME, methodName);
- if (securityEventType != null) {
- MDC.put(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
- HttpServletRequest req = null;
- if (args[0] != null && args[0] instanceof HttpServletRequest) {
- req = (HttpServletRequest) args[0];
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName);
- }
- }
- logger.debug(EELFLoggerDelegate.debugLogger, (methodName + " was invoked."));
- } catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.before() method. Details: " + e.getMessage());
- }
-
- return new Object[] { "" };
- }
-
- /**
- *
- * @param securityEventType
- * @param result
- * @param args
- * @param returnArgs
- * @param passOnArgs
- */
- public void after(SecurityEventTypeEnum securityEventType, String result, Object[] args, Object[] returnArgs,
- Object[] passOnArgs) {
- try {
- String className = "";
- if (passOnArgs[0] != null) {
- className = passOnArgs[0].toString();
- }
-
- String methodName = "";
- if (passOnArgs[1] != null) {
- methodName = passOnArgs[1].toString();
- }
-
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
-
- String appName = appService.getDefaultAppName();
- if (appName == null || appName == "") {
- appName = SystemProperties.SDK_NAME;
- }
-
- if (MDC.get(SystemProperties.TARGET_SERVICE_NAME) == null
- || MDC.get(SystemProperties.TARGET_SERVICE_NAME) == "") {
- MDC.put(SystemProperties.TARGET_SERVICE_NAME, methodName);
- }
-
- if (MDC.get(SystemProperties.TARGET_ENTITY) == null || MDC.get(SystemProperties.TARGET_ENTITY) == "") {
- MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE");
- }
-
- MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP,
- MDC.get(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP));
- MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
- this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP),
- MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP));
-
- logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed.");
- logger.debug(EELFLoggerDelegate.debugLogger, "Finished executing " + methodName + ".");
-
- if (securityEventType != null) {
-
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
- MDC.get(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP));
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
- this.calculateDateTimeDifference(MDC.get(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
- MDC.get(SystemProperties.AUDITLOG_END_TIMESTAMP));
-
- this.logSecurityMessage(logger, securityEventType, result, methodName);
-
- // clear when finishes audit logging
- MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
- MDC.remove(SystemProperties.PARTNER_NAME);
- MDC.remove(SystemProperties.MDC_LOGIN_ID);
- MDC.remove(SystemProperties.PROTOCOL);
- MDC.remove(SystemProperties.FULL_URL);
- MDC.remove(Configuration.MDC_SERVICE_NAME);
- MDC.remove(SystemProperties.RESPONSE_CODE);
- MDC.remove(SystemProperties.STATUS_CODE);
- MDC.remove(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.AUDITLOG_END_TIMESTAMP);
- }
-
- MDC.remove(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.METRICSLOG_END_TIMESTAMP);
- MDC.remove(SystemProperties.MDC_TIMER);
- MDC.remove(SystemProperties.TARGET_ENTITY);
- MDC.remove(SystemProperties.TARGET_SERVICE_NAME);
- } catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.after() method. Details: " + e.getMessage());
- }
- }
-
- /**
- *
- * @param logger
- * @param securityEventType
- * @param result
- * @param restMethod
- */
- private void logSecurityMessage(EELFLoggerDelegate logger, SecurityEventTypeEnum securityEventType, String result,
- String restMethod) {
- StringBuilder additionalInfoAppender = new StringBuilder();
- String auditMessage = "";
-
- additionalInfoAppender.append(String.format("%s request was received.", restMethod));
-
- // Status code
- MDC.put(SystemProperties.STATUS_CODE, result);
-
- String fullURL = MDC.get(SystemProperties.FULL_URL);
- if (fullURL != null && fullURL != "") {
- additionalInfoAppender.append(" Request-URL:" + MDC.get(SystemProperties.FULL_URL));
- }
-
- auditMessage = AuditLogFormatter.getInstance().createMessage(MDC.get(SystemProperties.PROTOCOL),
- securityEventType.name(), MDC.get(SystemProperties.MDC_LOGIN_ID), additionalInfoAppender.toString());
-
- logger.info(EELFLoggerDelegate.auditLogger, auditMessage);
- }
-
- /**
- *
- * @param beginDateTime
- * @param endDateTime
- */
- private void calculateDateTimeDifference(String beginDateTime, String endDateTime) {
- if (beginDateTime != null && endDateTime != null) {
- try {
- Date beginDate = ecompLogDateFormat.parse(beginDateTime);
- Date endDate = ecompLogDateFormat.parse(endDateTime);
- String timeDifference = String.format("%d ms", endDate.getTime() - beginDate.getTime());
- MDC.put(SystemProperties.MDC_TIMER, timeDifference);
- } catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.calculateDateTimeDifference() method. Details: "
- + e.getMessage());
- }
- }
- }
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAspect.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAspect.java
deleted file mode 100644
index 3138d21a..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/EELFLoggerAspect.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * ================================================================================
- * eCOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
-package org.openecomp.portalsdk.core.logging.aspect;
-
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Pointcut;
-import org.openecomp.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-
-
-@Aspect
-@org.springframework.context.annotation.Configuration
-public class EELFLoggerAspect {
-
- @Autowired
- EELFLoggerAdvice advice;
-
- /*
- * Point-cut expression to handle all INCOMING_REST_MESSAGES
- */
- @Pointcut("execution(public * org.openecomp.portalsdk.core.controller.*.*(..))")
- public void incomingAuditMessages() {}
-
- @Around("incomingAuditMessages() && @annotation(auditLog)")
- public Object logAuditMethodAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
- return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
- }
-
- @Around("incomingAuditMessages() && @within(auditLog)")
- public Object logAuditMethodClassAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
- return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
- }
-
- /*
- * Point cut expression to capture metrics logging
- */
- @Pointcut("execution(public * *(..))")
- public void publicMethod() {}
-
- @Around("publicMethod() && @within(metricsLog)")
- public Object logMetricsClassAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
- return this.logAroundMethod(joinPoint, null);
- }
-
- @Around("publicMethod() && @annotation(metricsLog)")
- public Object logMetricsMethodAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
- return this.logAroundMethod(joinPoint, null);
- }
-
- private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
- //Before
- Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
- Object[] returnArgs = advice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
-
- //Execute the actual method
- Object result = null;
- String restStatus = "COMPLETE";
- try {
- result = joinPoint.proceed();
- } catch(Exception e) {
- restStatus = "ERROR";
- }
-
- //After
- advice.after(securityEventType, restStatus, joinPoint.getArgs(), returnArgs, passOnArgs);
-
- return result;
- }
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/MetricsLog.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/MetricsLog.java
deleted file mode 100644
index f795ffb1..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/logging/aspect/MetricsLog.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-
- * ================================================================================
- * eCOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
-package org.openecomp.portalsdk.core.logging.aspect;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface MetricsLog {
- String value() default "";
-}