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.transport.FieldsValidator;
45 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
46 import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
47 import org.springframework.beans.factory.annotation.Autowired;
50 @org.springframework.context.annotation.Configuration
51 public class EPEELFLoggerAspect {
53 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPEELFLoggerAspect.class);
56 EPEELFLoggerAdvice epAdvice;
59 * Point-cut expression to handle all INCOMING_REST_MESSAGES
61 @Pointcut("execution(public * org.onap.portalapp.portal.controller.*.*(..))")
62 public void incomingAuditMessages() {}
65 * Handles all INCOMING_REST_MESSAGES from kpiDashboard
67 @Pointcut("execution(public * org.onap.portalapp.kpidash.controller.*.*(..))")
68 public void kpiDashboardAuditMessages() {}
71 * Point-cut expression to handle all session management INCOMING_REST_MESSAGES
73 @Pointcut("execution(public * org.onap.portalapp.controller.sessionmgt.*.*(..))")
74 public void sessionMgtIncomingAuditMessages() {}
77 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
79 @Pointcut("execution(public * org.onap.portalapp.controller.core.UserProfileController.*(..))")
80 public void userProfileIncomingAuditMessages() {}
83 * Point-cut expression to handle UserProfileController INCOMING_REST_MESSAGES
85 @Pointcut("execution(public * org.onap.portalapp.controller.ONAPWelcomeController.*(..))")
86 public void welcomeIncomingAuditMessages() {}
89 * Point-cut expression to handle INCOMING Logout Rest Messages
91 @Pointcut("execution(public * org.onap.portalapp.controller.ECOMPLogoutController.*(..))")
92 public void logoutAuditMessages() {}
96 * Point-cut expression which handles all the OUTGOING_REST_MESSAGES.
98 @Pointcut("execution(public * org.onap.portalapp.portal.service.ApplicationsRestClientServiceImpl.*(..))")
99 public void outgoingAuditMessages() {}
102 * Point-cut expression to handle all the session management OUTGOING_REST_MESSAGES.
104 @Pointcut("execution(public * org.onap.portalapp.service.sessionmgt.SessionCommunication.*(..))")
105 public void sessionMgtOutgoingAuditMessages() {}
108 * Point-cut expression which handles all the LDAP_PHONEBOOK_USER_SEARCH calls.
110 @Pointcut("execution(public * org.onap.portalapp.portal.service.EPLdapServiceImpl.*(..))")
111 public void phoneBookSearchAuditMessages() {}
114 * Handles Audit, Metrics & Debug logging for the point-cut
115 * expression defined at class-level
117 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() || "
118 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @within(epAuditLog)")
119 public Object incomingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
120 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
124 * Handles Audit, Metrics & Debug logging for the point-cut
125 * expression defined at class-level
127 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @within(epAuditLog)")
128 public Object outgoingAuditMessagesAroundClass(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
129 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
134 * Handles Audit, Metrics & Debug logging for the point-cut
135 * expression defined at method-level
137 @Around("(outgoingAuditMessages() || sessionMgtOutgoingAuditMessages()) && @annotation(epAuditLog)")
138 public Object outgoingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
139 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE);
143 * Handles Audit, Metrics & Debug logging for the point-cut
144 * expression defined at method-level
146 @Around("(incomingAuditMessages() || kpiDashboardAuditMessages() || sessionMgtIncomingAuditMessages() ||"
147 + "userProfileIncomingAuditMessages() || welcomeIncomingAuditMessages()) && @annotation(epAuditLog)")
148 public Object incomingAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
149 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
152 @Around("@annotation(epAuditLog)")
153 public Object loginAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
154 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGIN_ATTEMPT);
157 @Around("logoutAuditMessages() && @annotation(epAuditLog)")
158 public Object logoutAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
159 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.FE_LOGOUT);
162 @Around("phoneBookSearchAuditMessages() && @annotation(epAuditLog)")
163 public Object phonebookSearchAuditMessagesAroundMethod(ProceedingJoinPoint joinPoint, EPAuditLog epAuditLog) throws Throwable {
164 return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH);
167 private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
169 Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName()};
170 Object[] returnArgs = epAdvice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
172 //Call the actual method
173 Object result = null;
174 String statusCode = "COMPLETE";
175 String responseCode = "200";
177 result = joinPoint.proceed();
178 } catch(Exception e) {
179 logger.error(EELFLoggerDelegate.errorLogger, "logAroundMethod failed", e);
180 statusCode = "ERROR";
181 responseCode = "500"; //Internal server error
185 if (securityEventType!=null) {
187 statusCode = "ERROR";
188 //Check if there is an internal response code
189 //and use it if the caller function has configured it.
190 responseCode = epAdvice.getInternalResponseCode();
191 if (responseCode==null||responseCode=="") {
192 responseCode = "500"; //Internal server error
194 } else if (result instanceof FieldsValidator) {
195 FieldsValidator fieldsValidator = (FieldsValidator) result;
196 if (fieldsValidator!=null && fieldsValidator.httpStatusCode!=null) {
197 responseCode = fieldsValidator.httpStatusCode.toString();
203 epAdvice.after(securityEventType, statusCode, responseCode, joinPoint.getArgs(), returnArgs, passOnArgs);
209 @Pointcut("execution(* *(..))")
210 public void performMetricsLogging() {}
212 @Around("performMetricsLogging() && @within(epMetricsLog)")
213 public Object metricsLoggingAroundClass(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
214 return this.logAroundMethod(joinPoint, null);
217 @Around("performMetricsLogging() && @annotation(epMetricsLog)")
218 public Object metricsLoggingAroundMethod(ProceedingJoinPoint joinPoint, EPMetricsLog epMetricsLog) throws Throwable {
219 return this.logAroundMethod(joinPoint, null);