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.core.validator;
22
23 import org.opensaml.saml2.core.Assertion;
24 import org.opensaml.xml.util.DatatypeHelper;
25 import org.opensaml.xml.validation.ValidationException;
26 import org.opensaml.xml.validation.Validator;
27
28
29
30
31 public class AssertionSchemaValidator implements Validator<Assertion> {
32
33
34 public AssertionSchemaValidator() {
35
36 }
37
38
39 public void validate(Assertion assertion) throws ValidationException {
40 validateIssuer(assertion);
41 validateVersion(assertion);
42 validateID(assertion);
43 validateIssueInstant(assertion);
44 }
45
46
47
48
49
50
51
52 protected void validateIssuer(Assertion assertion) throws ValidationException {
53 if (assertion.getIssuer() == null) {
54 throw new ValidationException("Issuer is required element");
55 }
56 }
57
58
59
60
61
62
63
64 protected void validateVersion(Assertion assertion) throws ValidationException {
65 if (assertion.getVersion() == null) {
66 throw new ValidationException("Version is required attribute");
67 }
68 }
69
70
71
72
73
74
75
76 protected void validateID(Assertion assertion) throws ValidationException {
77 if (DatatypeHelper.isEmpty(assertion.getID())) {
78 throw new ValidationException("ID is required attribute");
79 }
80 }
81
82
83
84
85
86
87
88 protected void validateIssueInstant(Assertion assertion) throws ValidationException {
89 if (assertion.getIssueInstant() == null) {
90 throw new ValidationException("IssueInstant is required attribute");
91 }
92 }
93 }