2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.logging.aop;
40 import org.aspectj.lang.ProceedingJoinPoint;
41 import org.aspectj.lang.annotation.Around;
42 import org.aspectj.lang.annotation.Aspect;
43 import org.aspectj.lang.annotation.Pointcut;
44 import org.openecomp.portalapp.portal.transport.FieldsValidator;
45 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
46 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
47 import org.openecomp.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
48 import org.springframework.beans.factory.annotation.Autowired;
51 @org.springframework.context.annotation.Configuration
52 public class EPEELFLoggerAspect {
54 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPEELFLoggerAspect.class);
57 EPEELFLoggerAdvice epAdvice;
60 * Point-cut expression to handle all INCOMING_REST_MESSAGES
62 @Pointcut("execution(public * org.openecomp.portalapp.portal.controller.*.*(..))")
63 public void incomingAuditMessages() {}
66 * Handles all INCOMING_REST_MESSAGES from kpiDashboard
68 @Pointcut("execution(public * org.openecomp.portalapp.kpidash.controller.*.*(..))")
69 public void kpiDashboardAuditMessages() {}
72 * Point-cut expression to handle all session management INCOMING_REST_MESSAGES
74 @Pointcut("execution(public * org.openecomp.portalapp.controller.sessionmgt.*.*(..))")
75 public void sessionMgtIncomingAuditMessages() {}
78 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
80 @Pointcut("execution(public * org.openecomp.portalapp.controller.core.UserProfileController.*(..))")
81 public void userProfileIncomingAuditMessages() {}
84 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
86 @Pointcut("execution(public * org.openecomp.portalapp.controller.ONAPWelcomeController.*(..))")
87 public void welcomeIncomingAuditMessages() {}
90 * Point-cut expression to handle INCOMING Logout Rest Messages
92 @Pointcut("execution(public * org.openecomp.portalapp.controller.ECOMPLogoutController.*(..))")
93 public void logoutAuditMessages() {}
97 * Point-cut expression which handles all the OUTGOING_REST_MESSAGES.
99 @Pointcut("execution(public * org.openecomp.portalapp.portal.service.ApplicationsRestClientServiceImpl.*(..))")
100 public void outgoingAuditMessages() {}
103 * Point-cut expression to handle all the session management OUTGOING_REST_MESSAGES.
105 @Pointcut("execution(public * org.openecomp.portalapp.service.sessionmgt.SessionCommunication.*(..))")
106 public void sessionMgtOutgoingAuditMessages() {}
109 * Point-cut expression which handles all the LDAP_PHONEBOOK_USER_SEARCH calls.
111 @Pointcut("execution(public * org.openecomp.portalapp.portal.service.EPLdapServiceImpl.*(..))")
112 public void phoneBookSearchAuditMessages() {}
115 * Handles Audit, Metrics & Debug logging for the point-cut
116 * expression defined at class-level
118 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() || "
119 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @within(epAuditLog)")
120 public Object incomingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
121 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
125 * Handles Audit, Metrics & Debug logging for the point-cut
126 * expression defined at class-level
128 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @within(epAuditLog)")
129 public Object outgoingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
130 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
135 * Handles Audit, Metrics & Debug logging for the point-cut
136 * expression defined at method-level
138 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @annotation(epAuditLog)")
139 public Object outgoingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
140 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
144 * Handles Audit, Metrics & Debug logging for the point-cut
145 * expression defined at method-level
147 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() ||"
148 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @annotation(epAuditLog)")
149 public Object incomingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
150 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
153 @Around("@annotation(epAuditLog)")
154 public Object loginAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
155 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGIN_ATTEMPT);
158 @Around("logoutAuditMessages() && @annotation(epAuditLog)")
159 public Object logoutAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
160 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGOUT);
163 @Around("phoneBookSearchAuditMessages() && @annotation(epAuditLog)")
164 public Object phonebookSearchAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
165 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH);
168 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
170 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName()};
171 Object[] returnArgs = epAdvice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
173 //Call the actual method
174 Object result = null;
175 String statusCode = "COMPLETE";
176 String responseCode = "200";
178 result = joinPoint.proceed();
179 } catch(Exception e) {
180 logger.error(EELFLoggerDelegate.errorLogger, "logAroundMethod failed", e);
181 statusCode = "ERROR";
182 responseCode = "500"; //Internal server error
186 if (securityEventType!=null) {
188 statusCode = "ERROR";
189 //Check if there is an internal response code
190 //and use it if the caller function has configured it.
191 responseCode = epAdvice.getInternalResponseCode();
192 if (responseCode==null||responseCode=="") {
193 responseCode = "500"; //Internal server error
195 } else if (result instanceof FieldsValidator) {
196 FieldsValidator fieldsValidator = (FieldsValidator) result;
197 if (fieldsValidator!=null && fieldsValidator.httpStatusCode!=null) {
198 responseCode = fieldsValidator.httpStatusCode.toString();
204 epAdvice.after(securityEventType, statusCode, responseCode, joinPoint.getArgs(), returnArgs, passOnArgs);
210 @Pointcut("execution(* *(..))")
211 public void performMetricsLogging() {}
213 @Around("performMetricsLogging() && @within(epMetricsLog)")
214 public Object metricsLoggingAroundClass(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
215 return this.logAroundMethod(joinPoint, null);
218 @Around("performMetricsLogging() && @annotation(epMetricsLog)")
219 public Object metricsLoggingAroundMethod(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
220 return this.logAroundMethod(joinPoint, null);