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.portalapp.portal.logging.aop;
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.portalapp.portal.transport.FieldsValidator;
27 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.openecomp.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
30 import org.springframework.beans.factory.annotation.Autowired;
33 @org.springframework.context.annotation.Configuration
34 public class EPEELFLoggerAspect {
36 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPEELFLoggerAspect.class);
39 EPEELFLoggerAdvice epAdvice;
42 * Point-cut expression to handle all INCOMING_REST_MESSAGES
44 @Pointcut("execution(public * org.openecomp.portalapp.portal.controller.*.*(..))")
45 public void incomingAuditMessages() {}
48 * Handles all INCOMING_REST_MESSAGES from kpiDashboard
50 @Pointcut("execution(public * org.openecomp.portalapp.kpidash.controller.*.*(..))")
51 public void kpiDashboardAuditMessages() {}
54 * Point-cut expression to handle all session management INCOMING_REST_MESSAGES
56 @Pointcut("execution(public * org.openecomp.portalapp.controller.sessionmgt.*.*(..))")
57 public void sessionMgtIncomingAuditMessages() {}
60 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
62 @Pointcut("execution(public * org.openecomp.portalapp.controller.UserProfileController.*(..))")
63 public void userProfileIncomingAuditMessages() {}
66 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
68 @Pointcut("execution(public * org.openecomp.portalapp.controller.WelcomeController.*(..))")
69 public void welcomeIncomingAuditMessages() {}
72 * Point-cut expression to handle INCOING Logout Rest Messages
74 @Pointcut("execution(public * org.openecomp.portalapp.controller.ECOMPLogoutController.*(..))")
75 public void logoutAuditMessages() {}
79 * Point-cut expression which handles all the OUTGOING_REST_MESSAGES.
81 @Pointcut("execution(public * org.openecomp.portalapp.portal.service.ApplicationsRestClientServiceImpl.*(..))")
82 public void outgoingAuditMessages() {}
85 * Point-cut expression to handle all the session management OUTGOING_REST_MESSAGES.
87 @Pointcut("execution(public * org.openecomp.portalapp.service.sessionmgt.SessionCommunication.*(..))")
88 public void sessionMgtOutgoingAuditMessages() {}
91 * Point-cut expression which handles all the LDAP_PHONEBOOK_USER_SEARCH calls.
93 @Pointcut("execution(public * org.openecomp.portalapp.portal.service.EPLdapServiceImpl.*(..))")
94 public void phoneBookSearchAuditMessages() {}
97 * Handles Audit, Metrics & Debug logging for the point-cut
98 * expression defined at class-level
100 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() || "
101 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @within(epAuditLog)")
102 public Object incomingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
103 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
107 * Handles Audit, Metrics & Debug logging for the point-cut
108 * expression defined at class-level
110 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @within(epAuditLog)")
111 public Object outgoingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
112 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
117 * Handles Audit, Metrics & Debug logging for the point-cut
118 * expression defined at method-level
120 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @annotation(epAuditLog)")
121 public Object outgoingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
122 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
126 * Handles Audit, Metrics & Debug logging for the point-cut
127 * expression defined at method-level
129 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() ||"
130 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @annotation(epAuditLog)")
131 public Object incomingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
132 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
135 @Around("@annotation(epAuditLog)")
136 public Object loginAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
137 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGIN_ATTEMPT);
140 @Around("logoutAuditMessages() && @annotation(epAuditLog)")
141 public Object logoutAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
142 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGOUT);
145 @Around("phoneBookSearchAuditMessages() && @annotation(epAuditLog)")
146 public Object phonebookSearchAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
147 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH);
150 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
152 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName()};
153 Object[] returnArgs = epAdvice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
155 //Call the actual method
156 Object result = null;
157 String statusCode = "COMPLETE";
158 String responseCode = "200";
160 result = joinPoint.proceed();
161 } catch(Exception e) {
162 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
163 statusCode = "ERROR";
164 responseCode = "500"; //Internal server error
168 if (securityEventType!=null) {
170 statusCode = "ERROR";
171 //Check if there is an internal response code
172 //and use it if the caller function has configured it.
173 responseCode = epAdvice.getInternalResponseCode();
174 if (responseCode==null||responseCode=="") {
175 responseCode = "500"; //Internal server error
177 } else if (result instanceof FieldsValidator) {
178 FieldsValidator fieldsValidator = (FieldsValidator) result;
179 if (fieldsValidator!=null && fieldsValidator.httpStatusCode!=null) {
180 responseCode = fieldsValidator.httpStatusCode.toString();
186 epAdvice.after(securityEventType, statusCode, responseCode, joinPoint.getArgs(), returnArgs, passOnArgs);
192 @Pointcut("execution(* *(..))")
193 public void performMetricsLogging() {}
195 @Around("performMetricsLogging() && @within(epMetricsLog)")
196 public Object metricsLoggingAroundClass(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
197 return this.logAroundMethod(joinPoint, null);
200 @Around("performMetricsLogging() && @annotation(epMetricsLog)")
201 public Object metricsLoggingAroundMethod(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
202 return this.logAroundMethod(joinPoint, null);