diff options
7 files changed, 226 insertions, 47 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index 68257861..44919b1c 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -94,7 +94,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { String fisTmpFile = null; TempFileHelper helper = pdfObject.getStatus().getTempFileHelper(); - + PDDocument doc = null; try { fisTmpFile = helper.getStaticFilename(); @@ -104,7 +104,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { FileInputStream fis = new FileInputStream(new File(fisTmpFile)); - PDDocument doc = pdfObject.getDocument(); + doc = pdfObject.getDocument(); PDSignature signature = new PDSignature(); signature.setFilter(COSName.getPDFName(signer.getPDFFilter())); // default @@ -402,6 +402,14 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { logger.error(MessageResolver.resolveMessage("error.pdf.sig.01"), e); throw new PdfAsException("error.pdf.sig.01", e); } finally { + if(doc != null) { + try { + doc.close(); + } catch (IOException e) { + logger.debug("Failed to close COS Doc!", e); + // Ignore + } + } logger.info("Signature done!"); } diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java new file mode 100644 index 00000000..b9277c09 --- /dev/null +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java @@ -0,0 +1,109 @@ +package at.gv.egiz.pdfas.web.client.test; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import sun.misc.IOUtils; +import at.gv.egiz.pdfas.api.ws.PDFASBulkSignRequest; +import at.gv.egiz.pdfas.api.ws.PDFASBulkSignResponse; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; +import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; +import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; +import at.gv.egiz.pdfas.web.client.RemotePDFSigner; + +public class BulkRequestThread implements Runnable { + private Thread t; + private String threadName; + private RemotePDFSigner signer; + PDFASSignParameters signParameters; + private byte[] inputData; + int bulkSize; + int queries; + + public BulkRequestThread(String name, URL endpoint, int queries, int bulkSize) + throws IOException { + threadName = name; + this.queries = queries; + this.bulkSize = bulkSize; + System.out.println("Creating " + threadName); + + signer = new RemotePDFSigner(endpoint, false); + + FileInputStream fis = new FileInputStream( + "/home/afitzek/Documents/arm_arm.pdf"); + inputData = IOUtils.readFully(fis, -1, true); + + signParameters = new PDFASSignParameters(); + signParameters.setConnector(Connector.JKS); + signParameters.setPosition(null); + signParameters.setProfile("SIGNATURBLOCK_DE"); + + } + + private PDFASSignRequest getNewRequest() { + PDFASSignRequest request = new PDFASSignRequest(); + request.setInputData(inputData); + request.setParameters(signParameters); + request.setRequestID(UUID.randomUUID().toString()); + return request; + } + + private PDFASBulkSignRequest getBlukRequest(int count) { + + List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>(); + for (int i = 0; i < count; i++) { + bulk.add(getNewRequest()); + } + + PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest(); + bulkRequest.setSignRequests(bulk); + + return bulkRequest; + } + + public void run() { + System.out.println("Running " + threadName); + try { + for (int i = 0; i < queries; i++) { + System.out.println("Thread: " + threadName + ", " + i); + PDFASBulkSignResponse responses = signer + .signPDFDokument(getBlukRequest(bulkSize)); + + for (int j = 0; j < responses.getSignResponses().size(); j++) { + PDFASSignResponse bulkresponse = responses + .getSignResponses().get(j); + System.out.println("Thread: " + threadName + ", " +"ID: " + bulkresponse.getRequestID()); + if (bulkresponse.getError() != null) { + System.out.println("Thread: " + threadName + ", " + "ERROR: " + bulkresponse.getError()); + } else { + System.out.println("Thread: " + threadName + ", " + "OK"); + } + } + Thread.sleep(50); + } + } catch (InterruptedException e) { + System.out.println("Thread " + threadName + " interrupted."); + } + System.out.println("Thread " + threadName + " exiting."); + } + + public void start() { + System.out.println("Starting " + threadName); + if (t == null) { + t = new Thread(this, threadName); + t.start(); + } + } + + public void join() throws InterruptedException { + if(t != null) { + t.join(); + } + } +} diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java new file mode 100644 index 00000000..17a98276 --- /dev/null +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java @@ -0,0 +1,34 @@ +package at.gv.egiz.pdfas.web.client.test; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class PerformanceTest { + public static void main(String[] args) { + try { + List<BulkRequestThread> threads = new ArrayList<BulkRequestThread>(); + + URL endpoint = new URL( + "http://localhost:8080/pdf-as-web/wssign?wsdl"); + + for (int i = 0; i < 10; i++) { + threads.add(new BulkRequestThread("T" + i, endpoint, 10, 10)); + } + + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).start(); + } + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).join(); + } + + System.out.println("DONE"); + + } catch (Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java index 161e45cc..e7696ceb 100644 --- a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java @@ -20,7 +20,7 @@ public class SimpleTest { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream( - "/home/afitzek/simple.pdf"); + "/home/afitzek/Documents/arm_arm.pdf"); byte[] inputData = IOUtils.readFully(fis, -1, true); PDFASSignParameters signParameters = new PDFASSignParameters(); @@ -33,62 +33,64 @@ public class SimpleTest { request.setParameters(signParameters); request.setRequestID("SOME TEST ID"); - URL endpoint = new URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl"); - //URL endpoint = new URL( - // "http://localhost:8080/pdf-as-web/wssign?wsdl"); + // URL endpoint = new + // URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl"); + URL endpoint = new URL( + "http://localhost:8080/pdf-as-web/wssign?wsdl"); RemotePDFSigner signer = new RemotePDFSigner(endpoint, false); - System.out.println("Simple Request:"); - byte[] outputFile = signer.signPDFDokument(inputData, - signParameters); + /* + * System.out.println("Simple Request:"); byte[] outputFile = + * signer.signPDFDokument(inputData, signParameters); + * + * FileOutputStream fos = new FileOutputStream( + * "/home/afitzek/simple_request_signed.pdf"); + * fos.write(outputFile); fos.close(); + * + * System.out.println("Simple Request Obj:"); PDFASSignResponse + * response = signer.signPDFDokument(request); + * + * if (response.getSignedPDF() != null) { FileOutputStream fos2 = + * new FileOutputStream( + * "/home/afitzek/simple_request_obj_signed.pdf"); + * fos2.write(response.getSignedPDF()); fos2.close(); } + * + * if(response.getError() != null) { System.out.println("ERROR: " + + * response.getError()); } + */ - FileOutputStream fos = new FileOutputStream( - "/home/afitzek/simple_request_signed.pdf"); - fos.write(outputFile); - fos.close(); - - System.out.println("Simple Request Obj:"); - PDFASSignResponse response = signer.signPDFDokument(request); - - if (response.getSignedPDF() != null) { - FileOutputStream fos2 = new FileOutputStream( - "/home/afitzek/simple_request_obj_signed.pdf"); - fos2.write(response.getSignedPDF()); - fos2.close(); - } - - if(response.getError() != null) { - System.out.println("ERROR: " + response.getError()); - } - List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>(); - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { bulk.add(request); } PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest(); bulkRequest.setSignRequests(bulk); - - System.out.println("Bulk Request:"); - PDFASBulkSignResponse responses = signer.signPDFDokument(bulkRequest); - - for(int i = 0; i < responses.getSignResponses().size(); i++) { - PDFASSignResponse bulkresponse = responses.getSignResponses().get(i); - System.out.println("ID: " + bulkresponse.getRequestID()); - - if (bulkresponse.getSignedPDF() != null) { - FileOutputStream fos2 = new FileOutputStream( - "/home/afitzek/simple_request_obj_signed_"+ i +".pdf"); - fos2.write(bulkresponse.getSignedPDF()); - fos2.close(); - } - - if(bulkresponse.getError() != null) { - System.out.println("ERROR: " + bulkresponse.getError()); + + for (int j = 0; j < 10; j++) { + System.out.println("Bulk Request:"); + PDFASBulkSignResponse responses = signer + .signPDFDokument(bulkRequest); + + for (int i = 0; i < responses.getSignResponses().size(); i++) { + PDFASSignResponse bulkresponse = responses + .getSignResponses().get(i); + System.out.println("ID: " + bulkresponse.getRequestID()); + /* + * if (bulkresponse.getSignedPDF() != null) { + * FileOutputStream fos2 = new FileOutputStream( + * "/home/afitzek/simple_request_obj_signed_"+ i +".pdf"); + * fos2.write(bulkresponse.getSignedPDF()); fos2.close(); } + */ + if (bulkresponse.getError() != null) { + System.out.println("ERROR: " + bulkresponse.getError()); + } else { + System.out.println("OK"); + } } } - + System.out.println("Done!"); } catch (Throwable e) { e.printStackTrace(); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index f073ca56..4555d6a1 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -44,6 +44,7 @@ public class WebConfiguration { public static final String PDF_AS_WORK_DIR = "pdfas.dir"; public static final String MOA_SS_ENABLED = "moa.enabled"; + public static final String SOAP_SIGN_ENABLED = "soap.sign.enabled"; public static final String KEYSTORE_ENABLED = "ks.enabled"; public static final String KEYSTORE_FILE = "ks.file"; @@ -161,6 +162,16 @@ public class WebConfiguration { return false; } + public static boolean getSoapSignEnabled() { + String value = properties.getProperty(SOAP_SIGN_ENABLED); + if(value != null) { + if(value.equals("true")) { + return true; + } + } + return false; + } + public static boolean isShowErrorDetails() { String value = properties.getProperty(ERROR_DETAILS); if(value != null) { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index 5c0f94c4..0f33056e 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -348,8 +348,14 @@ public class PdfAsHelper { IPlainSigner signer; if (params.getConnector().equals(Connector.MOA)) { + if(!WebConfiguration.getMOASSEnabled()) { + throw new PdfAsWebException("MOA connector disabled."); + } signer = new PAdESSigner(new MOAConnector(config)); } else if(params.getConnector().equals(Connector.JKS)) { + if(!WebConfiguration.getKeystoreEnabled()) { + throw new PdfAsWebException("JKS connector disabled."); + } signer = new PKCS7DetachedSigner( WebConfiguration.getKeystoreFile(), WebConfiguration.getKeystoreAlias(), diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java index c8283d28..07ffd7c4 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java @@ -28,6 +28,7 @@ public class PDFASSigningImpl implements PDFASSigning { public byte[] signPDFDokument(byte[] inputDocument, PDFASSignParameters parameters) { + checkSoapSignEnabled(); try { return PdfAsHelper.synchornousServerSignature(inputDocument, parameters); @@ -42,6 +43,7 @@ public class PDFASSigningImpl implements PDFASSigning { } public PDFASSignResponse signPDFDokument(PDFASSignRequest request) { + checkSoapSignEnabled(); if (request == null) { logger.warn("SOAP Sign Request is null!"); return null; @@ -62,6 +64,7 @@ public class PDFASSigningImpl implements PDFASSigning { } public PDFASBulkSignResponse signPDFDokument(PDFASBulkSignRequest request) { + checkSoapSignEnabled(); List<PDFASSignResponse> responses = new ArrayList<PDFASSignResponse>(); if (request.getSignRequests() != null) { for (int i = 0; i < request.getSignRequests().size(); i++) { @@ -83,4 +86,10 @@ public class PDFASSigningImpl implements PDFASSigning { } } + private void checkSoapSignEnabled() { + if(!WebConfiguration.getSoapSignEnabled()) { + throw new WebServiceException("Service disabled!"); + } + } + } |