Skip to content

Commit 48cb11b

Browse files
committed
Do not depend directly on any JAXB artifacts
Using only what is provided by signature-api-specification-jaxb
1 parent 1e69d60 commit 48cb11b

File tree

4 files changed

+28
-62
lines changed

4 files changed

+28
-62
lines changed

NOTICE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ This software includes third party software subject to the following licenses:
1515
Apache HttpComponents Core HTTP/2 under Apache License, Version 2.0
1616
Apache HttpCore under Apache License, Version 2.0
1717
Digipost Certificate Validator under The Apache Software License, Version 2.0
18-
istack common utility code runtime under Eclipse Distribution License - v 1.0
18+
Digipost com.sun.xml.bind JAXB Service Loader under The Apache Software License, Version 2.0
1919
Jakarta Activation under EDL 1.0
20-
Jakarta Activation API jar under EDL 1.0
21-
Jakarta XML Binding API under Eclipse Distribution License - v 1.0
22-
JAXB Runtime under Eclipse Distribution License - v 1.0
20+
JavaBeans Activation Framework API jar under CDDL/GPLv2+CE
21+
jaxb-api under CDDL 1.1 or GPL2 w/ CPE
2322
JAXB2 Basics - Runtime under BSD-Style License
2423
JCL 1.2 implemented over SLF4J under Apache License, Version 2.0
24+
Old JAXB Core under CDDL+GPL License
25+
Old JAXB Runtime under Eclipse Distribution License - v 1.0
2526
Posten signering - API JAXB Classes under The Apache Software License, Version 2.0
2627
Posten signering - API Schema under The Apache Software License, Version 2.0
2728
Posten signering - Java API Client Library under The Apache Software License, Version 2.0
2829
SLF4J API Module under MIT License
29-
TXW2 Runtime under Eclipse Distribution License - v 1.0
3030

3131

pom.xml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<maven.compiler.source>1.8</maven.compiler.source>
1818
<maven.compiler.target>1.8</maven.compiler.target>
1919
<project.previousVersion>set_with_-Dproject.previousVersion=X.Y</project.previousVersion>
20-
<signature.api.version>3.0.0-RC4</signature.api.version>
20+
<signature.api.version>old-is-older-SNAPSHOT</signature.api.version>
2121
<slf4j.version>1.7.36</slf4j.version>
2222
</properties>
2323

@@ -75,18 +75,6 @@
7575
<version>5.2.1</version>
7676
</dependency>
7777

78-
<dependency>
79-
<groupId>jakarta.xml.bind</groupId>
80-
<artifactId>jakarta.xml.bind-api</artifactId>
81-
<version>2.3.3</version>
82-
</dependency>
83-
<dependency>
84-
<groupId>org.glassfish.jaxb</groupId>
85-
<artifactId>jaxb-runtime</artifactId>
86-
<version>2.3.8</version>
87-
<scope>runtime</scope>
88-
</dependency>
89-
9078
<dependency>
9179
<groupId>commons-io</groupId>
9280
<artifactId>commons-io</artifactId>
@@ -172,11 +160,18 @@
172160
<version>0.33</version>
173161
<scope>test</scope>
174162
</dependency>
163+
175164
<dependency>
176165
<groupId>com.github.tomakehurst</groupId>
177166
<artifactId>wiremock-jre8</artifactId>
178167
<version>2.35.0</version>
179168
<scope>test</scope>
169+
<exclusions>
170+
<exclusion>
171+
<groupId>jakarta.xml.bind</groupId>
172+
<artifactId>jakarta.xml.bind-api</artifactId>
173+
</exclusion>
174+
</exclusions>
180175
</dependency>
181176
</dependencies>
182177

src/main/java/no/digipost/signature/client/asice/signature/XAdESArtifacts.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
11
package no.digipost.signature.client.asice.signature;
22

33
import no.digipost.signature.api.xml.thirdparty.xades.QualifyingProperties;
4+
import no.digipost.signature.jaxb.JaxbMarshaller;
45
import org.w3c.dom.Document;
56
import org.w3c.dom.Element;
67
import org.w3c.dom.Node;
78
import org.w3c.dom.NodeList;
89

9-
import javax.xml.bind.JAXBContext;
10-
import javax.xml.bind.JAXBException;
11-
import javax.xml.bind.Marshaller;
12-
import javax.xml.transform.dom.DOMResult;
13-
10+
import static java.util.Collections.singleton;
1411
import static java.util.stream.IntStream.range;
1512

1613
final class XAdESArtifacts {
1714

18-
private static Marshaller marshaller;
19-
20-
static {
21-
try {
22-
marshaller = JAXBContext.newInstance(QualifyingProperties.class).createMarshaller();
23-
} catch (JAXBException e) {
24-
throw new RuntimeException(e);
25-
}
26-
}
15+
private static JaxbMarshaller marshaller = new JaxbMarshaller(singleton(QualifyingProperties.class));
2716

2817

2918
public static XAdESArtifacts from(QualifyingProperties qualifyingProperties) {
30-
DOMResult domResult = new DOMResult();
31-
try {
32-
marshaller.marshal(qualifyingProperties, domResult);
33-
} catch (JAXBException e) {
34-
throw new RuntimeException(
35-
"Failed to marshal qualifying properties, because " +
36-
e.getClass().getSimpleName() + " '" + e.getMessage() + "'", e);
37-
}
38-
return from((Document) domResult.getNode());
19+
return from(marshaller.marshalToDomDocument(qualifyingProperties));
3920
}
4021

4122
private static XAdESArtifacts from(Document qualifyingPropertiesDocument) {

src/test/java/no/digipost/signature/client/asice/signature/CreateSignatureTest.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@
1313
import no.digipost.signature.client.asice.ASiCEAttachable;
1414
import no.digipost.signature.client.core.DocumentType;
1515
import no.digipost.signature.client.security.KeyStoreConfig;
16+
import no.digipost.signature.jaxb.JaxbMarshaller;
1617
import org.junit.jupiter.api.BeforeEach;
1718
import org.junit.jupiter.api.Test;
1819

19-
import javax.xml.bind.JAXBContext;
20-
import javax.xml.bind.JAXBException;
21-
import javax.xml.bind.Unmarshaller;
22-
import javax.xml.transform.stream.StreamSource;
23-
24-
import java.io.ByteArrayInputStream;
2520
import java.math.BigInteger;
2621
import java.time.Clock;
2722
import java.time.ZoneId;
2823
import java.time.ZonedDateTime;
2924
import java.util.Base64;
25+
import java.util.HashSet;
3026
import java.util.List;
3127

3228
import static java.util.Arrays.asList;
@@ -36,7 +32,7 @@
3632
import static org.hamcrest.Matchers.notNullValue;
3733
import static uk.co.probablyfine.matchers.Java8Matchers.where;
3834

39-
public class CreateSignatureTest {
35+
class CreateSignatureTest {
4036

4137
private CreateSignature createSignature;
4238

@@ -48,16 +44,10 @@ public class CreateSignatureTest {
4844
private KeyStoreConfig noekkelpar;
4945
private List<ASiCEAttachable> files;
5046

51-
private static final Unmarshaller unmarshaller; static {
52-
try {
53-
unmarshaller = JAXBContext.newInstance(XAdESSignatures.class, QualifyingProperties.class).createUnmarshaller();
54-
} catch (JAXBException e) {
55-
throw new RuntimeException(e);
56-
}
57-
}
47+
private static final JaxbMarshaller unmarshaller = new JaxbMarshaller(new HashSet<>(asList(XAdESSignatures.class, QualifyingProperties.class)));
5848

5949
@BeforeEach
60-
public void setUp() {
50+
void setUp() {
6151
noekkelpar = TestKonfigurasjon.CLIENT_KEYSTORE;
6252
files = asList(
6353
file("dokument.pdf", "hoveddokument-innhold".getBytes(), DocumentType.PDF.getMediaType()),
@@ -69,7 +59,7 @@ public void setUp() {
6959
}
7060

7161
@Test
72-
public void test_generated_signatures() throws JAXBException {
62+
void test_generated_signatures() {
7363
/*
7464
* Expected signature value (Base-64 encoded) from the given keys, files, and time of the signing.
7565
* If this changes, something has changed in the signature implementation, and must be investigated!
@@ -81,7 +71,7 @@ public void test_generated_signatures() throws JAXBException {
8171
"nBa0FMipG5jtqUPYJJMTt56wIJlwQ95PhGIEYtdRYwxlgSau9Bw+wYmD4NU0K0hw6FgBQ/UDF87T5Zr7HTPWPMwpngkWg==";
8272

8373
Signature signature = createSignature.createSignature(files, noekkelpar);
84-
XAdESSignatures xAdESSignatures = (XAdESSignatures) unmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(signature.getContent())));
74+
XAdESSignatures xAdESSignatures = unmarshaller.unmarshal(signature.getContent(), XAdESSignatures.class);
8575

8676
assertThat(xAdESSignatures, where(XAdESSignatures::getSignatures, hasSize(1)));
8777
no.digipost.signature.api.xml.thirdparty.xmldsig.Signature dSignature = xAdESSignatures.getSignatures().get(0);
@@ -91,10 +81,10 @@ public void test_generated_signatures() throws JAXBException {
9181
}
9282

9383
@Test
94-
public void test_xades_signed_properties() throws JAXBException {
84+
void test_xades_signed_properties() {
9585
Signature signature = createSignature.createSignature(files, noekkelpar);
9686

97-
XAdESSignatures xAdESSignatures = (XAdESSignatures) unmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(signature.getContent())));
87+
XAdESSignatures xAdESSignatures = unmarshaller.unmarshal(signature.getContent(), XAdESSignatures.class);
9888
no.digipost.signature.api.xml.thirdparty.xmldsig.Object object = xAdESSignatures.getSignatures().get(0).getObjects().get(0);
9989

10090
QualifyingProperties xadesProperties = (QualifyingProperties) object.getContent().get(0);
@@ -106,14 +96,14 @@ public void test_xades_signed_properties() throws JAXBException {
10696
}
10797

10898
@Test
109-
public void should_support_filenames_with_spaces_and_other_characters() throws JAXBException {
99+
void should_support_filenames_with_spaces_and_other_characters() {
110100
List<ASiCEAttachable> otherFiles = asList(
111101
file("dokument (2).pdf", "hoveddokument-innhold".getBytes(), DocumentType.PDF.getMediaType()),
112102
file("manifest.xml", "manifest-innhold".getBytes(), ASiCEAttachable.XML_MEDIATYPE)
113103
);
114104

115105
Signature signature = createSignature.createSignature(otherFiles, noekkelpar);
116-
XAdESSignatures xAdESSignatures = (XAdESSignatures) unmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(signature.getContent())));
106+
XAdESSignatures xAdESSignatures = unmarshaller.unmarshal(signature.getContent(), XAdESSignatures.class);
117107
String uri = xAdESSignatures.getSignatures().get(0).getSignedInfo().getReferences().get(0).getURI();
118108
assertThat(uri, is("dokument+%282%29.pdf"));
119109
}

0 commit comments

Comments
 (0)