001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * anguenot 018 * 019 * $Id: WebAccessLogActionListener.java 28475 2008-01-04 09:49:02Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.audit.web.access; 023 024import static org.jboss.seam.ScopeType.CONVERSATION; 025 026import java.security.Principal; 027 028import org.apache.commons.logging.Log; 029import org.apache.commons.logging.LogFactory; 030import org.jboss.seam.annotations.In; 031import org.jboss.seam.annotations.Name; 032import org.jboss.seam.annotations.Observer; 033import org.jboss.seam.annotations.Scope; 034import org.nuxeo.ecm.core.api.DocumentModel; 035import org.nuxeo.ecm.core.api.event.CoreEventConstants; 036import org.nuxeo.ecm.core.api.event.DocumentEventCategories; 037import org.nuxeo.ecm.core.event.Event; 038import org.nuxeo.ecm.core.event.EventService; 039import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 040import org.nuxeo.ecm.platform.audit.web.access.api.AccessLogObserver; 041import org.nuxeo.ecm.platform.audit.web.access.api.WebAccessConstants; 042import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 043import org.nuxeo.ecm.webapp.helpers.EventNames; 044import org.nuxeo.runtime.api.Framework; 045 046/** 047 * Access log action listener. 048 * <p> 049 * Responsible of logging web access. Attention, this will decrease the performances of the webapp. 050 * </p> 051 * 052 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a> 053 * @author <a href="mailto:vdutat@yahoo.fr">Vincent Dutat</a> 054 */ 055@Name("webAccessLogObserver") 056@Scope(CONVERSATION) 057public class WebAccessLogActionListener implements AccessLogObserver { 058 059 private static final long serialVersionUID = 1L; 060 061 private static final Log log = LogFactory.getLog(WebAccessLogActionListener.class); 062 063 @In(create = true) 064 protected NavigationContext navigationContext; 065 066 @In(create = true) 067 protected Principal currentUser; 068 069 @Observer(value = { EventNames.USER_ALL_DOCUMENT_TYPES_SELECTION_CHANGED }, create = true) 070 public void log() { 071 DocumentModel dm = navigationContext.getCurrentDocument(); 072 if (dm == null) { 073 return; 074 } 075 DocumentEventContext ctx = new DocumentEventContext(navigationContext.getCurrentDocument().getCoreSession(), 076 currentUser, dm); 077 ctx.setCategory(DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); 078 ctx.setProperty(CoreEventConstants.DOC_LIFE_CYCLE, dm.getCurrentLifeCycleState()); 079 ctx.setProperty(CoreEventConstants.SESSION_ID, dm.getSessionId()); 080 Event event = ctx.newEvent(WebAccessConstants.EVENT_ID); 081 EventService evtService = Framework.getService(EventService.class); 082 log.debug("Sending scheduled event id=" + WebAccessConstants.EVENT_ID + ", category=" 083 + DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); 084 evtService.fireEvent(event); 085 } 086}