Skip to content

Commit

Permalink
Merge branch 'Hemuu:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemuu authored Mar 28, 2023
2 parents d7c5a7b + 1fb9070 commit 935324a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ try (FileOutputStream fos = new FileOutputStream(new File("example.signed.docx")
os.writeTo(fos);
}
```

Manual Building
=====

Building a JAR
-----
```bash
mvn clean package
```

Building a stand-alone JAR with included dependencies
-----
```bash
mvn clean package assembly:single
```

Running the PDF signing example
-----
```bash
java -jar target/laverca-rest-1.0.0-jar-with-dependencies.jar fi.methics.laverca.rest.SignPDF
```
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<artifactId>laverca-rest</artifactId>
<version>1.0.0</version>
<name>Laverca REST MSS client</name>

<build>
<plugins>
<plugin>
Expand All @@ -14,9 +15,18 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>

<repositories>
<repository>
<id>cefdigital</id>
<name>cefdigital</name>
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/fi/methics/laverca/rest/SignPDF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// (c) Copyright 2003-2023 Methics Oy. All rights reserved.
//
package fi.methics.laverca.rest;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import fi.methics.laverca.rest.util.SignatureProfile;

/**
* Example for PDF signing
* @see PdfSigner
*/
public class SignPDF {

private static final String REST_URL = "http://localhost:9060/rest/service";
private static final String AP_NAME = "TestAP";
private static final String PASSWORD = "9TMzfH7EKXETOB8FT5gz";
private static final String MSISDN = "35847001001";

private static final SignatureProfile SIG_PROFILE = SignatureProfile.of("http://alauda.mobi/nonRepudiation");

private static final String DOC_PATH = "./example.pdf";
private static final String SIGNED_DOC_PATH = "./example.signed.pdf";

public static void main(String[] args) throws Exception {

MssClient client = new MssClient.Builder().withRestUrl(REST_URL)
.withPassword(AP_NAME, PASSWORD)
.build();

PdfSigner signer = new PdfSigner(client);

File doc = new File(DOC_PATH);
InputStream is = new FileInputStream(doc);
ByteArrayOutputStream os = signer.signDocument(MSISDN,
"Please sign example.pdf",
is,
SIG_PROFILE);
try (FileOutputStream fos = new FileOutputStream(new File(SIGNED_DOC_PATH))) {
os.writeTo(fos);
}

System.out.println("Saved signed document to " + new File(SIGNED_DOC_PATH).getAbsolutePath());
}


}

0 comments on commit 935324a

Please sign in to comment.