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.controller;
40 import javax.servlet.http.HttpServletRequest;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.bind.annotation.RequestMethod;
46 import org.springframework.web.bind.annotation.RequestParam;
47 import org.springframework.web.bind.annotation.RestController;
49 import org.openecomp.portalsdk.core.domain.AuditLog;
50 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
51 import org.openecomp.portalsdk.core.service.AuditService;
52 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
53 import org.openecomp.portalapp.portal.domain.EPUser;
54 import org.openecomp.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
55 import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
56 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
57 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
58 import org.openecomp.portalapp.portal.utils.PortalConstants;
59 import org.openecomp.portalapp.util.EPUserUtils;
62 @RequestMapping("/portalApi/auditLog")
63 public class AuditLogController extends EPRestrictedBaseController {
64 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardController.class);
67 private AuditService auditService;
70 * Store audit log of the specified access type.
74 * @param affectedAppId
81 @RequestMapping(value = "/store", method = RequestMethod.GET, produces = "application/json")
82 public void auditLog(HttpServletRequest request, @RequestParam String affectedAppId, @RequestParam String type,
83 @RequestParam String comment) {
84 logger.debug(EELFLoggerDelegate.debugLogger, "auditLog: appId {}, type {], comment {}", affectedAppId, type,
86 String cd_type = null;
88 EPUser user = EPUserUtils.getUserSession(request);
89 /* Check type of Activity CD */
90 if (type.equals("app")) {
91 cd_type = AuditLog.CD_ACTIVITY_APP_ACCESS;
92 } else if (type.equals("tab")) {
93 cd_type = AuditLog.CD_ACTIVITY_TAB_ACCESS;
94 } else if (type.equals("functional")) {
95 cd_type = AuditLog.CD_ACTIVITY_FUNCTIONAL_ACCESS;
96 } else if (type.equals("leftMenu")) {
97 cd_type = AuditLog.CD_ACTIVITY_LEFT_MENU_ACCESS;
99 logger.error(EELFLoggerDelegate.errorLogger,
100 "Storing auditLog failed! Activity CD type is not correct.");
102 /* Store the audit log only if it contains valid Activity CD */
103 if (cd_type != null) {
104 AuditLog auditLog = new AuditLog();
105 auditLog.setActivityCode(cd_type);
107 * Check affectedAppId and comment and see if these two values are valid
109 if (comment != null && !comment.equals("") && !comment.equals("undefined"))
110 auditLog.setComments(EcompPortalUtils.truncateString(comment, PortalConstants.AUDIT_LOG_COMMENT_SIZE));
111 if (affectedAppId != null && !affectedAppId.equals("") && !affectedAppId.equals("undefined"))
112 auditLog.setAffectedRecordId(affectedAppId);
113 long userId = EPUserUtils.getUserId(request);
114 auditLog.setUserId(userId);
115 auditService.logActivity(auditLog, null);
118 MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
119 MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
120 logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage(
121 "AuditLogController.auditLog", cd_type, user.getOrgUserId(), affectedAppId, comment));
122 MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
123 MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
125 } catch (Exception e) {
126 logger.error(EELFLoggerDelegate.errorLogger, "auditLog failed", e);