001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * anguenot 016 * 017 * $Id: WebAccessLogActionListener.java 28475 2008-01-04 09:49:02Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.audit.web.access; 021 022import static org.jboss.seam.ScopeType.CONVERSATION; 023 024import java.security.Principal; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.jboss.seam.annotations.In; 029import org.jboss.seam.annotations.Name; 030import org.jboss.seam.annotations.Observer; 031import org.jboss.seam.annotations.Scope; 032import org.nuxeo.ecm.core.api.DocumentModel; 033import org.nuxeo.ecm.core.api.event.CoreEventConstants; 034import org.nuxeo.ecm.core.api.event.DocumentEventCategories; 035import org.nuxeo.ecm.core.event.Event; 036import org.nuxeo.ecm.core.event.EventService; 037import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 038import org.nuxeo.ecm.platform.audit.web.access.api.AccessLogObserver; 039import org.nuxeo.ecm.platform.audit.web.access.api.WebAccessConstants; 040import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 041import org.nuxeo.ecm.webapp.helpers.EventNames; 042import org.nuxeo.runtime.api.Framework; 043 044/** 045 * Access log action listener. 046 * <p> 047 * Responsible of logging web access. Attention, this will decrease the performances of the webapp. 048 * </p> 049 * 050 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a> 051 * @author <a href="mailto:vdutat@yahoo.fr">Vincent Dutat</a> 052 */ 053@Name("webAccessLogObserver") 054@Scope(CONVERSATION) 055public class WebAccessLogActionListener implements AccessLogObserver { 056 057 private static final long serialVersionUID = 1L; 058 059 private static final Log log = LogFactory.getLog(WebAccessLogActionListener.class); 060 061 @In(create = true) 062 protected NavigationContext navigationContext; 063 064 @In(create = true) 065 protected Principal currentUser; 066 067 @Observer(value = { EventNames.USER_ALL_DOCUMENT_TYPES_SELECTION_CHANGED }, create = true) 068 public void log() { 069 DocumentModel dm = navigationContext.getCurrentDocument(); 070 if (dm == null) { 071 return; 072 } 073 DocumentEventContext ctx = new DocumentEventContext(navigationContext.getCurrentDocument().getCoreSession(), 074 currentUser, dm); 075 ctx.setCategory(DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); 076 ctx.setProperty(CoreEventConstants.DOC_LIFE_CYCLE, dm.getCurrentLifeCycleState()); 077 ctx.setProperty(CoreEventConstants.SESSION_ID, dm.getSessionId()); 078 Event event = ctx.newEvent(WebAccessConstants.EVENT_ID); 079 EventService evtService = Framework.getService(EventService.class); 080 log.debug("Sending scheduled event id=" + WebAccessConstants.EVENT_ID + ", category=" 081 + DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); 082 evtService.fireEvent(event); 083 } 084}