aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java2
-rw-r--r--pdf-as-moa/src/generated/java/at/gv/e_government/reference/namespace/moa/_20020822/ContentBaseType.java2
-rw-r--r--pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java76
-rw-r--r--pdf-as-moa/src/main/resources/wsdl/MOA-SPSS-3.1.2.xsd9
4 files changed, 66 insertions, 23 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
index d031e2f7..2909095a 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
@@ -82,6 +82,8 @@ public interface IConfigurationConstants {
public static final String MOA_SIGN_KEY_ID = MOA_SS_KEY_IDENTIFIER;
public static final String MOA_SIGN_CERTIFICATE = MOA_SS_KEY_CERTIFICATE;
+ public static final String MOA_MTOM_ENABLED = "moa.sign.soap.mtom.enable";
+
/**
* MOA Verify URL configuration Key
diff --git a/pdf-as-moa/src/generated/java/at/gv/e_government/reference/namespace/moa/_20020822/ContentBaseType.java b/pdf-as-moa/src/generated/java/at/gv/e_government/reference/namespace/moa/_20020822/ContentBaseType.java
index 16510de7..477fb446 100644
--- a/pdf-as-moa/src/generated/java/at/gv/e_government/reference/namespace/moa/_20020822/ContentBaseType.java
+++ b/pdf-as-moa/src/generated/java/at/gv/e_government/reference/namespace/moa/_20020822/ContentBaseType.java
@@ -4,6 +4,7 @@ package at.gv.e_government.reference.namespace.moa._20020822;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
@@ -43,6 +44,7 @@ import javax.xml.bind.annotation.XmlType;
public class ContentBaseType {
@XmlElement(name = "Base64Content")
+ @XmlMimeType("application/octet-stream")
protected byte[] base64Content;
@XmlElement(name = "XMLContent")
protected XMLContentType xmlContent;
diff --git a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java
index cc739b9e..df155006 100644
--- a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java
+++ b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java
@@ -23,29 +23,31 @@
******************************************************************************/
package at.gv.egiz.pdfas.moa;
-import at.gv.e_government.reference.namespace.moa._20020822.*;
-import iaik.x509.X509Certificate;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.CertificateException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import javax.xml.ws.BindingProvider;
+import javax.xml.ws.soap.SOAPBinding;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.e_government.reference.namespace.moa._20020822.CMSContentBaseType;
import at.gv.e_government.reference.namespace.moa._20020822.CMSDataObjectInfoType.DataObject;
+import at.gv.e_government.reference.namespace.moa._20020822.CreateCMSSignatureRequest;
import at.gv.e_government.reference.namespace.moa._20020822.CreateCMSSignatureRequestType.SingleSignatureInfo;
import at.gv.e_government.reference.namespace.moa._20020822.CreateCMSSignatureRequestType.SingleSignatureInfo.DataObjectInfo;
+import at.gv.e_government.reference.namespace.moa._20020822.CreateCMSSignatureResponseType;
+import at.gv.e_government.reference.namespace.moa._20020822.ErrorResponseType;
+import at.gv.e_government.reference.namespace.moa._20020822.MetaInfoType;
import at.gv.e_government.reference.namespace.moa._20020822_.MOAFault;
import at.gv.e_government.reference.namespace.moa._20020822_.SignatureCreationPortType;
import at.gv.e_government.reference.namespace.moa._20020822_.SignatureCreationService;
@@ -66,6 +68,7 @@ import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature;
import at.gv.egiz.pdfas.lib.util.SignatureUtils;
import at.gv.egiz.sl.util.ISignatureConnector;
+import iaik.x509.X509Certificate;
public class MOAConnector implements ISignatureConnector,
IConfigurationConstants {
@@ -78,6 +81,7 @@ public class MOAConnector implements ISignatureConnector,
private X509Certificate certificate;
private String moaEndpoint;
private String keyIdentifier;
+ private boolean mtomEnabled;
public MOAConnector(Configuration config,
@@ -125,16 +129,23 @@ public class MOAConnector implements ISignatureConnector,
if (certificateValue.startsWith("http")) {
logger.debug("Loading certificate from url: " + certificateValue);
+ InputStream is = null;
try {
URL certificateURL = new URL(certificateValue);
-
- this.certificate = new X509Certificate(
- certificateURL.openStream());
+ is = certificateURL.openStream();
+ this.certificate = new X509Certificate();
+
} catch (MalformedURLException e) {
logger.error(certificateValue + " is not a valid url but starts with http!");
- throw new PdfAsWrappedIOException(new PdfAsException(
- certificateValue + " is not a valid url but!"));
- }
+ throw new PdfAsWrappedIOException(new PdfAsException(certificateValue + " is not a valid url but!"));
+
+ } finally {
+ if (is != null) {
+ is.close();
+
+ }
+ }
+
} else {
File certFile = new File(certificateValue);
@@ -154,9 +165,12 @@ public class MOAConnector implements ISignatureConnector,
this.moaEndpoint = config.getValue(MOA_SIGN_URL);
this.keyIdentifier = config.getValue(MOA_SIGN_KEY_ID);
+ this.mtomEnabled = parseConfigToBoolean(config.getValue(MOA_MTOM_ENABLED), false);
+ logger.info("MOA client {} SOAP with MTOM", this.mtomEnabled ? "enabled" : "disabled");
+
}
- public X509Certificate getCertificate(SignParameter parameter)
+ public X509Certificate getCertificate(SignParameter parameter)
throws PdfAsException {
return this.certificate;
}
@@ -173,12 +187,16 @@ public class MOAConnector implements ISignatureConnector,
*/
SignatureCreationService service = new SignatureCreationService();
- SignatureCreationPortType creationPort = service
- .getSignatureCreationPort();
+ SignatureCreationPortType creationPort = service.getSignatureCreationPort();
BindingProvider provider = (BindingProvider) creationPort;
- provider.getRequestContext().put(
- BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.moaEndpoint);
+ provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.moaEndpoint);
+ if (this.mtomEnabled) {
+ if (provider.getBinding() instanceof SOAPBinding) {
+ ((SOAPBinding) provider.getBinding()).setMTOMEnabled(true);
+ }
+ }
+
CreateCMSSignatureRequest request = new CreateCMSSignatureRequest();
request.setKeyIdentifier(this.keyIdentifier.trim());
SingleSignatureInfo sigInfo = new SingleSignatureInfo();
@@ -217,21 +235,24 @@ public class MOAConnector implements ISignatureConnector,
request.getSingleSignatureInfo().add(sigInfo);
requestedSignature.getStatus().getMetaInformations()
- .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE);
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE);
+
// TODO: Find a way to get MOA-SPSS Version
requestedSignature.getStatus().getMetaInformations()
- .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION, "UNKNOWN");
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION, "UNKNOWN");
CreateCMSSignatureResponseType response;
try {
response = creationPort.createCMSSignature(request);
+
} catch (MOAFault e) {
logger.warn("MOA signing failed!", e);
if (e.getFaultInfo() != null) {
- throw new PdfAsMOAException(e.getFaultInfo().getErrorCode()
- .toString(), e.getFaultInfo().getInfo(), "", "");
+ throw new PdfAsMOAException(e.getFaultInfo().getErrorCode().toString(), e.getFaultInfo().getInfo(), "", "");
+
} else {
throw new PdfAsMOAException("", e.getMessage(), "", "");
+
}
}
@@ -282,4 +303,17 @@ public class MOAConnector implements ISignatureConnector,
+ resp.getClass().getName());
}
}
+
+
+ private boolean parseConfigToBoolean(String value, boolean defaultValue) {
+ if (StringUtils.isNotEmpty(value)) {
+ return Boolean.valueOf(value);
+
+ } else {
+ return defaultValue;
+
+ }
+ }
+
+
}
diff --git a/pdf-as-moa/src/main/resources/wsdl/MOA-SPSS-3.1.2.xsd b/pdf-as-moa/src/main/resources/wsdl/MOA-SPSS-3.1.2.xsd
index d82fe3d1..51d9fe06 100644
--- a/pdf-as-moa/src/main/resources/wsdl/MOA-SPSS-3.1.2.xsd
+++ b/pdf-as-moa/src/main/resources/wsdl/MOA-SPSS-3.1.2.xsd
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- MOA SP/SS 2.0.0 Schema -->
-<xsd:schema xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://reference.e-government.gv.at/namespace/moa/20020822#" targetNamespace="http://reference.e-government.gv.at/namespace/moa/20020822#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.2">
+<xsd:schema xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+ xmlns="http://reference.e-government.gv.at/namespace/moa/20020822#"
+ targetNamespace="http://reference.e-government.gv.at/namespace/moa/20020822#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.2">
<xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="./W3C-XMLDSig.xsd"/>
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="./xml.xsd"/>
<!--########## Create CMS Signature ### -->
@@ -557,7 +561,8 @@
<xsd:complexContent>
<xsd:restriction base="ContentOptionalRefType">
<xsd:choice minOccurs="0">
- <xsd:element name="Base64Content" type="xsd:base64Binary"/>
+ <xsd:element name="Base64Content" type="xsd:base64Binary"
+ xmime:expectedContentTypes="application/octet-stream"/>
</xsd:choice>
</xsd:restriction>
</xsd:complexContent>