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