1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.xml.signature.validator;
18
19 import java.util.List;
20
21 import javax.xml.namespace.QName;
22
23 import org.opensaml.xml.XMLObject;
24 import org.opensaml.xml.signature.KeyValue;
25 import org.opensaml.xml.util.XMLConstants;
26 import org.opensaml.xml.validation.ValidationException;
27 import org.opensaml.xml.validation.Validator;
28
29
30
31
32 public class KeyValueSchemaValidator implements Validator<KeyValue> {
33
34
35 public void validate(KeyValue xmlObject) throws ValidationException {
36 validateChildrenPresence(xmlObject);
37 validateExtensionChildNamespace(xmlObject);
38 }
39
40
41
42
43
44
45
46 protected void validateChildrenPresence(KeyValue xmlObject) throws ValidationException {
47 List<XMLObject> children = xmlObject.getOrderedChildren();
48 if (children == null || children.isEmpty()) {
49 throw new ValidationException("No children were present in the KeyValue object");
50 }
51 if (children.size() > 1) {
52 throw new ValidationException("Invalid number of children were present in the KeyValue object");
53 }
54 }
55
56
57
58
59
60
61
62 protected void validateExtensionChildNamespace(KeyValue xmlObject) throws ValidationException {
63
64
65 XMLObject unknownChild = xmlObject.getUnknownXMLObject();
66 if (unknownChild == null) {
67 return;
68 }
69 QName childName = unknownChild.getElementQName();
70 if (XMLConstants.XMLSIG_NS.equals(childName.getNamespaceURI())) {
71 throw new ValidationException("KeyValue contains an illegal child extension element: " + childName);
72 }
73 }
74 }