2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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.onap.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.onap.portalapp.portal.logging.aop.EPAuditLog;
45 import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
46 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
47 import org.onap.portalapp.portal.transport.FieldsValidator;
48 import org.onap.portalapp.portal.utils.EcompPortalUtils;
49 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
50 import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
51 import org.springframework.beans.factory.annotation.Autowired;
54 @org.springframework.context.annotation.Configuration
55 public class EPEELFLoggerAspect {
57 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPEELFLoggerAspect.class);
60 EPEELFLoggerAdvice epAdvice;
63 * Point-cut expression to handle all INCOMING_REST_MESSAGES
65 @Pointcut("execution(public * org.onap.portalapp.portal.controller.*.*(..))")
66 public void incomingAuditMessages() {}
69 * Handles all INCOMING_REST_MESSAGES from kpiDashboard
71 @Pointcut("execution(public * org.onap.portalapp.kpidash.controller.*.*(..))")
72 public void kpiDashboardAuditMessages() {}
75 * Point-cut expression to handle all session management INCOMING_REST_MESSAGES
77 @Pointcut("execution(public * org.onap.portalapp.controller.sessionmgt.*.*(..))")
78 public void sessionMgtIncomingAuditMessages() {}
81 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
83 @Pointcut("execution(public * org.onap.portalapp.controller.core.UserProfileController.*(..))")
84 public void userProfileIncomingAuditMessages() {}
87 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
89 @Pointcut("execution(public * org.onap.portalapp.controller.ONAPWelcomeController.*(..))")
90 public void welcomeIncomingAuditMessages() {}
93 * Point-cut expression to handle INCOMING Logout Rest Messages
95 @Pointcut("execution(public * org.onap.portalapp.controller.ECOMPLogoutController.*(..))")
96 public void logoutAuditMessages() {}
100 * Point-cut expression which handles all the OUTGOING_REST_MESSAGES.
102 @Pointcut("execution(public * org.onap.portalapp.portal.service.ApplicationsRestClientServiceImpl.*(..))")
103 public void outgoingAuditMessages() {}
106 * Point-cut expression to handle all the session management OUTGOING_REST_MESSAGES.
108 @Pointcut("execution(public * org.onap.portalapp.service.sessionmgt.SessionCommunication.*(..))")
109 public void sessionMgtOutgoingAuditMessages() {}
112 * Point-cut expression which handles all the LDAP_PHONEBOOK_USER_SEARCH calls.
114 @Pointcut("execution(public * org.onap.portalapp.portal.service.EPLdapServiceImpl.*(..))")
115 public void phoneBookSearchAuditMessages() {}
118 * Handles Audit, Metrics & Debug logging for the point-cut
119 * expression defined at class-level
121 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() || "
122 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @within(epAuditLog)")
123 public Object incomingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
124 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
128 * Handles Audit, Metrics & Debug logging for the point-cut
129 * expression defined at class-level
131 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @within(epAuditLog)")
132 public Object outgoingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
133 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
138 * Handles Audit, Metrics & Debug logging for the point-cut
139 * expression defined at method-level
141 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @annotation(epAuditLog)")
142 public Object outgoingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
143 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
147 * Handles Audit, Metrics & Debug logging for the point-cut
148 * expression defined at method-level
150 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() ||"
151 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @annotation(epAuditLog)")
152 public Object incomingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
153 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
156 @Around("@annotation(epAuditLog)")
157 public Object loginAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
158 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGIN_ATTEMPT);
161 @Around("logoutAuditMessages() && @annotation(epAuditLog)")
162 public Object logoutAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
163 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGOUT);
166 @Around("phoneBookSearchAuditMessages() && @annotation(epAuditLog)")
167 public Object phonebookSearchAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
168 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH);
171 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
173 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName()};
174 Object[] returnArgs = epAdvice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
176 //Call the actual method
177 Object result = null;
178 String statusCode = "COMPLETE";
179 String responseCode = "200";
181 result = joinPoint.proceed();
182 } catch(Exception e) {
183 logger.error(EELFLoggerDelegate.errorLogger, "logAroundMethod failed", e);
184 statusCode = "ERROR";
185 responseCode = "500"; //Internal server error
189 if (securityEventType!=null) {
191 statusCode = "ERROR";
192 //Check if there is an internal response code
193 //and use it if the caller function has configured it.
194 responseCode = epAdvice.getInternalResponseCode();
195 if (responseCode==null||responseCode=="") {
196 responseCode = "500"; //Internal server error
198 } else if (result instanceof FieldsValidator) {
199 FieldsValidator fieldsValidator = (FieldsValidator) result;
200 if (fieldsValidator!=null && fieldsValidator.httpStatusCode!=null) {
201 responseCode = fieldsValidator.httpStatusCode.toString();
207 epAdvice.after(securityEventType, statusCode, responseCode, joinPoint.getArgs(), returnArgs, passOnArgs);
213 @Pointcut("execution(* *(..))")
214 public void performMetricsLogging() {}
216 @Around("performMetricsLogging() && @within(epMetricsLog)")
217 public Object metricsLoggingAroundClass(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
218 return this.logAroundMethod(joinPoint, null);
221 @Around("performMetricsLogging() && @annotation(epMetricsLog)")
222 public Object metricsLoggingAroundMethod(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
223 return this.logAroundMethod(joinPoint, null);