2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.core.logging.aspect;
22 import org.aspectj.lang.ProceedingJoinPoint;
23 import org.aspectj.lang.annotation.Around;
24 import org.aspectj.lang.annotation.Aspect;
25 import org.aspectj.lang.annotation.Pointcut;
26 import org.openecomp.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
27 import org.springframework.beans.factory.annotation.Autowired;
31 @org.springframework.context.annotation.Configuration
32 public class EELFLoggerAspect {
35 EELFLoggerAdvice advice;
38 * Point-cut expression to handle all INCOMING_REST_MESSAGES
40 @Pointcut("execution(public * org.openecomp.portalsdk.core.controller.*.*(..))")
41 public void incomingAuditMessages() {}
43 @Around("incomingAuditMessages() && @annotation(auditLog)")
44 public Object logAuditMethodAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
45 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
48 @Around("incomingAuditMessages() && @within(auditLog)")
49 public Object logAuditMethodClassAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
50 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
54 * Point cut expression to capture metrics logging
56 @Pointcut("execution(public * *(..))")
57 public void publicMethod() {}
59 @Around("publicMethod() && @within(metricsLog)")
60 public Object logMetricsClassAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
61 return this.logAroundMethod(joinPoint, null);
64 @Around("publicMethod() && @annotation(metricsLog)")
65 public Object logMetricsMethodAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
66 return this.logAroundMethod(joinPoint, null);
69 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
71 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
72 Object[] returnArgs = advice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
74 //Execute the actual method
76 String restStatus = "COMPLETE";
78 result = joinPoint.proceed();
79 } catch(Exception e) {
84 advice.after(securityEventType, restStatus, joinPoint.getArgs(), returnArgs, passOnArgs);