コード例 #1
0
  @Test
  public void testSignPDF() throws Exception {
    SignatureServiceImpl ssi = (SignatureServiceImpl) signatureService;

    // first user signs
    Blob origBlob = Blobs.createBlob(origPdfFile);
    assertEquals(UNSIGNED, ssi.getSigningStatus(origBlob, user));
    Blob signedBlob =
        signatureService.signPDF(origBlob, null, user, USER_KEY_PASSWORD, "test reason");
    assertNotNull(signedBlob);
    assertEquals(SIGNED_CURRENT, ssi.getSigningStatus(signedBlob, user));
    assertEquals(SIGNED_OTHER, ssi.getSigningStatus(signedBlob, user2));

    // try for the same user to sign the certificate again
    Blob signedBlobTwice = null;
    try {
      signedBlobTwice =
          signatureService.signPDF(signedBlob, null, user, USER_KEY_PASSWORD, "test reason");
      fail("Should raise AlreadySignedException");
    } catch (AlreadySignedException e) {
      // ok
    }

    // try for the second user to sign the certificate
    signedBlobTwice =
        signatureService.signPDF(signedBlob, null, user2, USER_KEY_PASSWORD, "test reason");
    assertNotNull(signedBlobTwice);
    assertEquals(SIGNED_CURRENT, ssi.getSigningStatus(signedBlobTwice, user));
    assertEquals(SIGNED_CURRENT, ssi.getSigningStatus(signedBlobTwice, user2));

    // test presence of multiple signatures
    List<String> names = getSignatureNames(signedBlobTwice);
    assertEquals(2, names.size());
    assertEquals(Arrays.asList("Signature2", "Signature1"), names);
  }
コード例 #2
0
  @Test
  public void testGetCertificates() throws Exception {
    SignatureServiceImpl ssi = (SignatureServiceImpl) signatureService;

    // sign the original PDF file
    Blob signedBlob =
        signatureService.signPDF(
            Blobs.createBlob(origPdfFile), null, user, USER_KEY_PASSWORD, "test reason");
    assertNotNull(signedBlob);
    // verify there are certificates in the signed file
    List<X509Certificate> certificates = ssi.getCertificates(signedBlob);
    assertTrue(
        "There has to be at least 1 certificate in a signed document", certificates.size() > 0);
    assertTrue(certificates.get(0).getSubjectDN().toString().contains("CN=Homer Simpson"));
  }