1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.xml.signature;
18
19 import java.util.List;
20
21 import org.apache.xml.security.Init;
22 import org.apache.xml.security.exceptions.XMLSecurityException;
23 import org.apache.xml.security.signature.XMLSignature;
24 import org.opensaml.xml.security.SecurityHelper;
25 import org.opensaml.xml.signature.impl.SignatureImpl;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32
33
34
35
36
37
38
39
40 public class Signer {
41
42
43 protected Signer() {
44
45 }
46
47
48
49
50
51
52
53 public static void signObjects(List<Signature> xmlObjects) throws SignatureException {
54 for (Signature xmlObject : xmlObjects) {
55 signObject(xmlObject);
56 }
57 }
58
59
60
61
62
63
64
65 public static void signObject(Signature signature) throws SignatureException {
66 Logger log = getLogger();
67 try {
68 XMLSignature xmlSignature = ((SignatureImpl) signature).getXMLSignature();
69
70 if (xmlSignature == null) {
71 log.error("Unable to compute signature, Signature XMLObject does not have the XMLSignature "
72 + "created during marshalling.");
73 throw new SignatureException("XMLObject does not have an XMLSignature instance, unable to compute signature");
74 }
75 log.debug("Computing signature over XMLSignature object");
76 xmlSignature.sign(SecurityHelper.extractSigningKey(signature.getSigningCredential()));
77 } catch (XMLSecurityException e) {
78 log.error("An error occured computing the digital signature", e);
79 throw new SignatureException("Signature computation error", e);
80 }
81 }
82
83
84
85
86
87
88 private static Logger getLogger() {
89 return LoggerFactory.getLogger(Signer.class);
90 }
91
92
93
94
95 static {
96 Logger log = getLogger();
97 if (!Init.isInitialized()) {
98 log.debug("Initializing XML security library");
99 Init.init();
100 }
101 }
102 }