001/* 002 * (C) Copyright 2012-2014 Nuxeo SA (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-2.1.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 * Vladimir Pasquier <vpasquier@nuxeo.com> 016 * Mickael Vachette <mv@nuxeo.com> 017 */ 018package org.nuxeo.ecm.platform.signature.core.operations; 019 020import org.nuxeo.ecm.automation.core.Constants; 021import org.nuxeo.ecm.automation.core.annotations.Context; 022import org.nuxeo.ecm.automation.core.annotations.Operation; 023import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 024import org.nuxeo.ecm.automation.core.annotations.Param; 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.platform.signature.api.sign.SignatureService; 028import org.nuxeo.ecm.platform.usermanager.UserManager; 029 030@Operation(id = SignPDF.ID, category = Constants.CAT_SERVICES, label = "Sign PDF", description = "Applies a digital signature to the" 031 + " input PDF.") 032public class SignPDF { 033 034 public static final String ID = "Services.SignPDF"; 035 036 @Context 037 protected UserManager userManager; 038 039 @Context 040 protected SignatureService signatureService; 041 042 @Param(name = "username", required = true, description = "The user ID for" + " signing PDF document.") 043 protected String username; 044 045 @Param(name = "password", required = true, description = "Certificate " + "password.") 046 protected String password; 047 048 @Param(name = "reason", required = true, description = "Signature reason.") 049 protected String reason; 050 051 @Param(name = "document", required = false, description = "Document reference.") 052 protected DocumentModel doc = null; 053 054 @OperationMethod 055 public Blob run(Blob blob) { 056 DocumentModel user = userManager.getUserModel(username); 057 return signatureService.signPDF(blob, doc, user, password, reason); 058 } 059}