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============================================
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.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
50 import org.springframework.beans.factory.annotation.Autowired;
53 @org.springframework.context.annotation.Configuration
54 public class EPEELFLoggerAspect {
56 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPEELFLoggerAspect.class);
59 EPEELFLoggerAdvice epAdvice;
62 * Point-cut expression to handle all INCOMING_REST_MESSAGES
64 @Pointcut("execution(public * org.onap.portalapp.portal.controller.*.*(..))")
65 public void incomingAuditMessages() {}
68 * Handles all INCOMING_REST_MESSAGES from kpiDashboard
70 @Pointcut("execution(public * org.onap.portalapp.kpidash.controller.*.*(..))")
71 public void kpiDashboardAuditMessages() {}
74 * Point-cut expression to handle all session management INCOMING_REST_MESSAGES
76 @Pointcut("execution(public * org.onap.portalapp.controller.sessionmgt.*.*(..))")
77 public void sessionMgtIncomingAuditMessages() {}
80 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
82 @Pointcut("execution(public * org.onap.portalapp.controller.core.UserProfileController.*(..))")
83 public void userProfileIncomingAuditMessages() {}
86 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
88 @Pointcut("execution(public * org.onap.portalapp.controller.ONAPWelcomeController.*(..))")
89 public void welcomeIncomingAuditMessages() {}
92 * Point-cut expression to handle INCOMING Logout Rest Messages
94 @Pointcut("execution(public * org.onap.portalapp.controller.ECOMPLogoutController.*(..))")
95 public void logoutAuditMessages() {}
99 * Point-cut expression which handles all the OUTGOING_REST_MESSAGES.
101 @Pointcut("execution(public * org.onap.portalapp.portal.service.ApplicationsRestClientServiceImpl.*(..))")
102 public void outgoingAuditMessages() {}
105 * Point-cut expression to handle all the session management OUTGOING_REST_MESSAGES.
107 @Pointcut("execution(public * org.onap.portalapp.service.sessionmgt.SessionCommunication.*(..))")
108 public void sessionMgtOutgoingAuditMessages() {}
111 * Point-cut expression which handles all the LDAP_PHONEBOOK_USER_SEARCH calls.
113 @Pointcut("execution(public * org.onap.portalapp.portal.service.EPLdapServiceImpl.*(..))")
114 public void phoneBookSearchAuditMessages() {}
117 * Handles Audit, Metrics & Debug logging for the point-cut
118 * expression defined at class-level
120 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() || "
121 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @within(epAuditLog)")
122 public Object incomingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
123 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
127 * Handles Audit, Metrics & Debug logging for the point-cut
128 * expression defined at class-level
130 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @within(epAuditLog)")
131 public Object outgoingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
132 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
137 * Handles Audit, Metrics & Debug logging for the point-cut
138 * expression defined at method-level
140 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @annotation(epAuditLog)")
141 public Object outgoingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
142 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
146 * Handles Audit, Metrics & Debug logging for the point-cut
147 * expression defined at method-level
149 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() ||"
150 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @annotation(epAuditLog)")
151 public Object incomingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
152 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
155 @Around("@annotation(epAuditLog)")
156 public Object loginAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
157 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGIN_ATTEMPT);
160 @Around("logoutAuditMessages() && @annotation(epAuditLog)")
161 public Object logoutAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
162 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGOUT);
165 @Around("phoneBookSearchAuditMessages() && @annotation(epAuditLog)")
166 public Object phonebookSearchAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
167 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH);
170 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
172 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName()};
173 Object[] returnArgs = epAdvice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
175 //Call the actual method
176 Object result = null;
177 String statusCode = "COMPLETE";
178 String responseCode = "200";
180 result = joinPoint.proceed();
181 } catch(Exception e) {
182 logger.error(EELFLoggerDelegate.errorLogger, "logAroundMethod failed", e);
183 statusCode = "ERROR";
184 responseCode = "500"; //Internal server error
188 if (securityEventType!=null) {
190 statusCode = "ERROR";
191 //Check if there is an internal response code
192 //and use it if the caller function has configured it.
193 responseCode = epAdvice.getInternalResponseCode();
194 if (responseCode==null||responseCode=="") {
195 responseCode = "500"; //Internal server error
197 } else if (result instanceof FieldsValidator) {
198 FieldsValidator fieldsValidator = (FieldsValidator) result;
199 if (fieldsValidator!=null && fieldsValidator.httpStatusCode!=null) {
200 responseCode = fieldsValidator.httpStatusCode.toString();
206 epAdvice.after(securityEventType, statusCode, responseCode, joinPoint.getArgs(), returnArgs, passOnArgs);
212 @Pointcut("execution(* *(..))")
213 public void performMetricsLogging() {}
215 @Around("performMetricsLogging() && @within(epMetricsLog)")
216 public Object metricsLoggingAroundClass(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
217 return this.logAroundMethod(joinPoint, null);
220 @Around("performMetricsLogging() && @annotation(epMetricsLog)")
221 public Object metricsLoggingAroundMethod(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
222 return this.logAroundMethod(joinPoint, null);