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