1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opensaml.saml2.metadata.validator;
22
23 import org.opensaml.saml2.metadata.KeyDescriptor;
24 import org.opensaml.xml.security.credential.UsageType;
25 import org.opensaml.xml.validation.ValidationException;
26 import org.opensaml.xml.validation.Validator;
27
28
29
30
31 public class KeyDescriptorSchemaValidator implements Validator<KeyDescriptor> {
32
33
34 public KeyDescriptorSchemaValidator() {
35
36 }
37
38
39 public void validate(KeyDescriptor keyDescriptor) throws ValidationException {
40 validateKeyInfo(keyDescriptor);
41 validateUse(keyDescriptor);
42 }
43
44
45
46
47
48
49
50 protected void validateKeyInfo(KeyDescriptor keyDescriptor) throws ValidationException {
51 if (keyDescriptor.getKeyInfo()==null) {
52 throw new ValidationException("KeyInfo required");
53 }
54 }
55
56
57
58
59
60
61
62 protected void validateUse(KeyDescriptor keyDescriptor) throws ValidationException {
63 UsageType use = keyDescriptor.getUse();
64 if (use == null) {
65 return;
66 }
67 if ( ! use.equals(UsageType.SIGNING)
68 && ! use.equals(UsageType.ENCRYPTION)
69 && ! use.equals(UsageType.UNSPECIFIED) ) {
70 throw new ValidationException("Invalid value for use attribute: " + use.toString());
71 }
72 }
73 }