2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.controller;
\r
22 import javax.servlet.http.HttpServletRequest;
\r
24 import org.slf4j.MDC;
\r
25 import org.springframework.beans.factory.annotation.Autowired;
\r
26 import org.springframework.web.bind.annotation.RequestMapping;
\r
27 import org.springframework.web.bind.annotation.RequestMethod;
\r
28 import org.springframework.web.bind.annotation.RequestParam;
\r
29 import org.springframework.web.bind.annotation.RestController;
\r
31 import org.openecomp.portalsdk.core.domain.AuditLog;
\r
32 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
33 import org.openecomp.portalsdk.core.service.AuditService;
\r
34 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
\r
35 import org.openecomp.portalapp.portal.domain.EPUser;
\r
36 import org.openecomp.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
\r
37 import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
\r
38 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
\r
39 import org.openecomp.portalapp.util.EPUserUtils;
\r
42 @RequestMapping("/portalApi/auditLog")
\r
43 public class AuditLogController extends EPRestrictedBaseController {
\r
44 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardController.class);
\r
47 private AuditService auditService;
\r
50 * Store audit log of the specified access type.
\r
53 * @param affectedAppId
\r
57 @RequestMapping(value = "/store", method = RequestMethod.GET, produces = "application/json")
\r
58 public void auditLog(HttpServletRequest request, @RequestParam String affectedAppId, @RequestParam String type,
\r
59 @RequestParam String comment) {
\r
60 logger.debug(EELFLoggerDelegate.debugLogger, "auditLog: appId {}, type {], comment {}",
\r
61 affectedAppId, type, comment);
\r
62 String cd_type = null;
\r
64 EPUser user = EPUserUtils.getUserSession(request);
\r
65 /* Check type of Activity CD */
\r
66 if (type.equals("app")) {
\r
67 cd_type = AuditLog.CD_ACTIVITY_APP_ACCESS;
\r
68 } else if (type.equals("tab")) {
\r
69 cd_type = AuditLog.CD_ACTIVITY_TAB_ACCESS;
\r
70 } else if (type.equals("functional")) {
\r
71 cd_type = AuditLog.CD_ACTIVITY_FUNCTIONAL_ACCESS;
\r
72 } else if (type.equals("leftMenu")) {
\r
73 cd_type = AuditLog.CD_ACTIVITY_LEFT_MENU_ACCESS;
\r
75 logger.error(EELFLoggerDelegate.errorLogger, "Storing auditLog failed! Activity CD type is not correct.");
\r
77 /* Store the audit log only if it contains valid Activity CD */
\r
78 if (cd_type != null) {
\r
79 AuditLog auditLog = new AuditLog();
\r
80 auditLog.setActivityCode(cd_type);
\r
82 * Check affectedAppId and comment and see if these two values are
\r
85 if (comment != null && !comment.equals("") && !comment.equals("undefined"))
\r
86 auditLog.setComments(comment);
\r
87 if (affectedAppId != null && !affectedAppId.equals("") && !affectedAppId.equals("undefined"))
\r
88 auditLog.setAffectedRecordId(affectedAppId);
\r
89 long userId = EPUserUtils.getUserId(request);
\r
90 auditLog.setUserId(userId);
\r
91 auditService.logActivity(auditLog, null);
\r
94 MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
\r
95 MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
\r
96 logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage("AuditLogController.auditLog",
\r
97 cd_type, user.getOrgUserId(), affectedAppId, comment));
\r
98 MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
\r
99 MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
\r
101 } catch (Exception e) {
\r
102 logger.error(EELFLoggerDelegate.errorLogger, "auditLog failed", e);
\r