@Test
  public void testSignPDFDocumentArchive() throws Exception {
    Blob pdfBlob = Blobs.createBlob(origPdfFile, "application/pdf", null, "foo.pdf");
    DocumentModel doc = session.createDocumentModel("File");
    doc.setPropertyValue("file:content", (Serializable) pdfBlob);

    Blob signedBlob =
        signatureService.signDocument(
            doc,
            user,
            USER_KEY_PASSWORD,
            "test",
            false,
            SigningDisposition.ARCHIVE,
            "foo archive.pdf");

    assertEquals("foo.pdf", signedBlob.getFilename());
    assertEquals(Arrays.asList("Signature1"), getSignatureNames(signedBlob));
    assertEquals(signedBlob, doc.getPropertyValue("file:content"));
    @SuppressWarnings("unchecked")
    List<Map<String, Serializable>> files =
        (List<Map<String, Serializable>>) doc.getPropertyValue("files:files");
    assertEquals(1, files.size());
    Blob archivedBlob = (Blob) files.get(0).get("file");
    assertEquals("application/pdf", archivedBlob.getMimeType());
    assertEquals("foo archive.pdf", archivedBlob.getFilename());
    assertEquals("foo archive.pdf", files.get(0).get("filename"));
  }
  @Test
  public void testResignDocument() throws Exception {
    Blob pdfBlob = Blobs.createBlob(signedPdfFile, "application/pdf", null, "foo.pdf");
    assertEquals(Arrays.asList("Signature1"), getSignatureNames(pdfBlob));

    DocumentModel doc = session.createDocumentModel("File");
    doc.setPropertyValue("file:content", (Serializable) pdfBlob);

    Blob signedBlob =
        signatureService.signDocument(
            doc, user, USER_KEY_PASSWORD, "test", false, SigningDisposition.REPLACE, null);

    assertEquals("foo.pdf", signedBlob.getFilename());
    assertEquals(Arrays.asList("Signature2", "Signature1"), getSignatureNames(signedBlob));
  }
  @Test
  public void testSignDocumentReplace() throws Exception {
    Blob txtBlob = Blobs.createBlob(helloTxtFile, "text/plain", null, "foo.txt");
    DocumentModel doc = session.createDocumentModel("File");
    doc.setPropertyValue("file:content", (Serializable) txtBlob);

    Blob signedBlob =
        signatureService.signDocument(
            doc, user, USER_KEY_PASSWORD, "test", false, SigningDisposition.REPLACE, null);

    assertEquals("foo.pdf", signedBlob.getFilename());
    assertEquals(Arrays.asList("Signature1"), getSignatureNames(signedBlob));
    assertEquals(signedBlob, doc.getPropertyValue("file:content"));
    assertEquals(Collections.emptyList(), doc.getPropertyValue("files:files"));
  }
Esempio n. 4
0
 @OperationMethod
 public Blob run(DocumentModel doc) throws OperationException {
   if (!(ctx.getPrincipal() instanceof NuxeoPrincipal)
       || !((NuxeoPrincipal) ctx.getPrincipal()).isAdministrator()) {
     throw new OperationException("Not allowed. You must be administrator to use this operation");
   }
   DocumentModel user = userManager.getUserModel(username);
   Blob originalBlob = doc.getAdapter(BlobHolder.class).getBlob();
   boolean originalIsPdf = MIME_TYPE_PDF.equals(originalBlob.getMimeType());
   // decide if we want PDF/A
   boolean pdfa = SignatureHelper.getPDFA();
   // decide disposition
   SigningDisposition disposition = SignatureHelper.getDisposition(originalIsPdf);
   // decide archive filename
   String filename = originalBlob.getFilename();
   String archiveFilename = SignatureHelper.getArchiveFilename(filename);
   return signatureService.signDocument(
       doc, user, password, reason, pdfa, disposition, archiveFilename);
 }
  @Test
  public void testSignDocumentAttach() throws Exception {
    Blob txtBlob = Blobs.createBlob(helloTxtFile, "text/plain", null, "foo.txt");
    DocumentModel doc = session.createDocumentModel("File");
    doc.setPropertyValue("file:content", (Serializable) txtBlob);

    Blob signedBlob =
        signatureService.signDocument(
            doc, user, USER_KEY_PASSWORD, "test", false, SigningDisposition.ATTACH, null);

    assertEquals("foo.pdf", signedBlob.getFilename());
    assertEquals(Arrays.asList("Signature1"), getSignatureNames(signedBlob));
    assertEquals(txtBlob, doc.getPropertyValue("file:content"));
    @SuppressWarnings("unchecked")
    List<Map<String, Serializable>> files =
        (List<Map<String, Serializable>>) doc.getPropertyValue("files:files");
    assertEquals(1, files.size());
    assertEquals(signedBlob, files.get(0).get("file"));
  }