001/* 002 * (C) Copyright 2010 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 * Nuxeo - initial API and implementation 018 */ 019package org.nuxeo.ecm.platform.routing.core.listener; 020 021import org.nuxeo.ecm.core.api.CoreSession; 022import org.nuxeo.ecm.core.api.security.ACE; 023import org.nuxeo.ecm.core.api.security.ACL; 024import org.nuxeo.ecm.core.api.security.ACP; 025import org.nuxeo.ecm.core.api.security.SecurityConstants; 026import org.nuxeo.ecm.core.event.Event; 027import org.nuxeo.ecm.core.event.EventListener; 028import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 029import org.nuxeo.ecm.platform.routing.api.DocumentRoute; 030import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants; 031 032/** 033 * Updates the security of the {@link DocumentRoute} so the user responsible for starting the route on a document can 034 * see the route. 035 * 036 * @author <a href="mailto:arussel@nuxeo.com">Alexandre Russel</a> 037 */ 038public class DocumentRoutingSecurityListener implements EventListener { 039 040 @Override 041 public void handleEvent(Event event) { 042 DocumentEventContext docCtx = (DocumentEventContext) event.getContext(); 043 DocumentRoute route = (DocumentRoute) docCtx.getProperty(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY); 044 String initiator = (String) docCtx.getProperty(DocumentRoutingConstants.INITIATOR_EVENT_CONTEXT_KEY); 045 CoreSession session = docCtx.getCoreSession(); 046 // initiator is a step validator 047 route.setCanValidateStep(session, initiator); 048 // initiator can see the route 049 ACP acp = route.getDocument().getACP(); 050 ACL acl = acp.getOrCreateACL(DocumentRoutingConstants.DOCUMENT_ROUTING_ACL); 051 acl.add(new ACE(initiator, SecurityConstants.READ, true)); 052 session.setACP(route.getDocument().getRef(), acp, true); 053 } 054 055}