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 private static Logger log = LoggerFactory.getLogger(Signer.class);
44
45
46 protected Signer() {
47
48 }
49
50
51
52
53
54
55
56 public static void signObjects(List<Signature> xmlObjects) throws SignatureException {
57 for (Signature xmlObject : xmlObjects) {
58 signObject(xmlObject);
59 }
60 }
61
62
63
64
65
66
67
68 public static void signObject(Signature signature) throws SignatureException {
69 try {
70 XMLSignature xmlSignature = ((SignatureImpl) signature).getXMLSignature();
71
72 if (xmlSignature == null) {
73 log.error("Unable to compute signature, Signature XMLObject does not have the XMLSignature "
74 + "created during marshalling.");
75 throw new SignatureException("XMLObject does not have an XMLSignature instance, unable to compute signature");
76 }
77 log.debug("Computing signature over XMLSignature object");
78 xmlSignature.sign(SecurityHelper.extractSigningKey(signature.getSigningCredential()));
79 } catch (XMLSecurityException e) {
80 log.error("An error occured computing the digital signature", e);
81 throw new SignatureException("Signature computation error", e);
82 }
83 }
84
85
86
87
88 static {
89 if (!Init.isInitialized()) {
90 log.debug("Initializing XML security library");
91 Init.init();
92 }
93 }
94 }