Skip to content

Commit

Permalink
Merge pull request #80 from slovensko-digital/fix-signing
Browse files Browse the repository at this point in the history
Fix signing
  • Loading branch information
jsuchal authored Dec 2, 2022
2 parents ccc8c84 + cdc9e75 commit 447af2e
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 27 deletions.
49 changes: 36 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<gson.version>2.8.9</gson.version>
<apache.httpcomponents.version>4.5.13</apache.httpcomponents.version>
<pdfjs.version>2.10.377</pdfjs.version>
<saxon.version>10.6</saxon.version>
<xerces.version>2.12.1</xerces.version>
<main.class>com.octosign.whitelabel.ui.Main</main.class>
</properties>

Expand Down Expand Up @@ -79,19 +77,38 @@
<version>${apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>${saxon.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>11.4</version>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -108,7 +125,7 @@

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.9.0</version>
</plugin>

Expand Down Expand Up @@ -186,7 +203,8 @@
<configuration>
<url>https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs.version}</url>
<fromDir>cmaps</fromDir>
<toDir>${project.resources[0].directory}/com/octosign/whitelabel/ui/vendor/pdfjs/cmaps</toDir>
<toDir>${project.resources[0].directory}/com/octosign/whitelabel/ui/vendor/pdfjs/cmaps
</toDir>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -308,13 +326,18 @@
<version>3.0.0</version>
<configuration>
<executable>bash</executable>
<workingDirectory>${project.build.scriptSourceDirectory}${file.separator}resources</workingDirectory>
<workingDirectory>${project.build.scriptSourceDirectory}${file.separator}resources
</workingDirectory>
<arguments>
<argument>${project.build.scriptSourceDirectory}${file.separator}package.sh</argument>
<argument>${jlink.jdk.path}${file.separator}bin${file.separator}jpackage</argument>
<argument>${project.build.directory}${file.separator}${project.artifactId}-${project.version}-${platform}</argument>
<argument>
${project.build.directory}${file.separator}${project.artifactId}-${project.version}-${platform}
</argument>
<argument>${project.build.directory}${file.separator}preparedJDK</argument>
<argument>${project.basedir}${file.separator}src${file.separator}main${file.separator}resources${file.separator}com${file.separator}octosign${file.separator}whitelabel</argument>
<argument>
${project.basedir}${file.separator}src${file.separator}main${file.separator}resources${file.separator}com${file.separator}octosign${file.separator}whitelabel
</argument>
<argument>${platform}</argument>
<argument>${project.version}</argument>
<argument>${project.build.directory}</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public XMLDocument(Document document) {
super(document);
}

static {
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
}

public String getTransformed(String transformation) {
if (isNullOrBlank(transformation))
throw new IntegrationException(Code.MISSING_INPUT, "body.parameters.transformation missing!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,21 @@ private String getDocumentContent() throws TransformerException {
var xmlSource = new DOMSource(document);
var outputTarget = new StreamResult(new StringWriter());

var transformerFactory= TransformerFactory.newInstance();
var transformerFactory = TransformerFactory.newInstance();
transformerFactory.newTransformer().transform(xmlSource, outputTarget);

return outputTarget.getWriter().toString();
}

private Element createXMLDataContainer() {
var element = document.createElement("XMLDataContainer");
var element = document.createElementNS(containerXmlns, "XMLDataContainer");
element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
if (containerXmlns != null)
element.setAttribute("xmlns", containerXmlns);

return element;
}

private Element createXMLData() {
var element = document.createElement("XMLData");
var element = document.createElementNS(containerXmlns, "XMLData");
element.setAttribute("ContentType", "application/xml; charset=UTF-8");
element.setAttribute("Identifier", identifierUri);
element.setAttribute("Version", identifierVersion);
Expand All @@ -178,7 +175,7 @@ private Element createXMLData() {
}

private Element createUsedSchemasReferenced() {
var element = document.createElement("UsedSchemasReferenced");
var element = document.createElementNS(containerXmlns, "UsedSchemasReferenced");
if (isPresent(xsdSchema) || isPresent(xsltSchema)) {
var documentXmlnsNode = document.getFirstChild().getAttributes().getNamedItem("xmlns");
if (documentXmlnsNode != null)
Expand Down Expand Up @@ -224,7 +221,7 @@ private static String toURIString(String xmlns, String suffix) {
}

private Element createUsedXSDReference() {
var element = document.createElement("UsedXSDReference");
var element = document.createElementNS(containerXmlns,"UsedXSDReference");
element.setAttribute("TransformAlgorithm", canonicalizationMethod);
element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm));
element.setAttribute("DigestValue", computeDigest(xsdSchema));
Expand All @@ -234,7 +231,7 @@ private Element createUsedXSDReference() {
}

private Element createUsedPresentationSchemaReference() {
var element = document.createElement("UsedPresentationSchemaReference");
var element = document.createElementNS(containerXmlns, "UsedPresentationSchemaReference");
element.setAttribute("TransformAlgorithm", canonicalizationMethod);
element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm));
element.setAttribute("DigestValue", computeDigest(xsltSchema));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.octosign.whitelabel.communication.document;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class XMLDocumentTest {
@Test
void testTransformsPlainHtmlWithoutAddingNamespaces() throws IOException {
var input = this.getClass().getResourceAsStream("abc.xml").readAllBytes();
var transformation = new String(this.getClass().getResourceAsStream("abc.xslt").readAllBytes());

XMLDocument doc = new XMLDocument(new Document("id1", "test.xml", input));
String transformed = doc.getTransformed(transformation);

assertEquals(-1, transformed.lastIndexOf(":p>"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OutputDocument xmlns="http://schemas.gov.sk/form/36126624.PovolenieZdravotnictvo.sk/1.6">
<Rozhodnutie>
<UvodVyroku>
<p>Úrad pre dohľad nad zdravotnou starostlivosťou, právny odbor (ďalej len „úrad“), ako orgán príslušný na vydanie povolenia podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z. o zdravotných poisťovniach, dohľade nad zdravotnou starostlivosťou a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 581/2004 Z.z.“), § 11 ods. 3 a § 21 ods. 1 zákona č. 578/2004 Z.z. o poskytovateľoch zdravotnej starostlivosti, zdravotníckych pracovníkoch, stavovských organizáciách v zdravotníctve a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 578/2004 Z.z.“) a § 5 a § 6 ods. 2 zákona č. 71/1967 Zb. o správnom konaní (správny poriadok) v znení neskorších predpisov (ďalej len „Správny poriadok“) v súlade s § 46 a § 47 Správneho poriadku a § 25 ods. 1 zákona č. 578/2004 Z.z. rozhodol t a k t o:</p>
<p>Na základe žiadosti zo dňa XXXXXXX žiadateľa XXXXXXX, XXXXX, právna forma spoločnosť s ručením obmedzeným, IČO: XXXXX, zastúpenej štatutárnym orgánom XXXXXXXXXX (ďalej len „žiadateľ“) o vydanie povolenia na prevádzkovanie ambulancie záchrannej zdravotnej služby (ďalej len „ZZS“), a to ambulancie XXXXXXX v sídle stanice XXXXXX, podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z., § 11 ods. 3 písm. d), § 21 ods. 1 zákona č. 578/2004 Z.z. v súlade s § 12 ods. 4 a 5, § 14 ods. 11 a § 15 ods. 1 a 2 zákona č. 578/2004 Z.z.</p>
</UvodVyroku>
</Rozhodnutie>
</OutputDocument>
Loading

0 comments on commit 447af2e

Please sign in to comment.