1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opensaml.saml1.core.validator;
22
23 import java.util.List;
24
25 import org.opensaml.saml1.core.Assertion;
26 import org.opensaml.saml1.core.Statement;
27 import org.opensaml.xml.util.DatatypeHelper;
28 import org.opensaml.xml.validation.ValidationException;
29 import org.opensaml.xml.validation.Validator;
30
31
32
33
34 public class AssertionSchemaValidator implements Validator<Assertion> {
35
36
37 public void validate(Assertion assertion) throws ValidationException {
38 validateVersion(assertion);
39 validateId(assertion);
40 validateIssuer(assertion);
41 validateIssueInstant(assertion);
42 validateStatements(assertion);
43 }
44
45
46
47
48
49
50 protected void validateVersion(Assertion assertion) throws ValidationException {
51 if ((assertion.getMajorVersion() != 1) &&
52 (assertion.getMinorVersion() != 0 || assertion.getMinorVersion() != 1)) {
53 throw new ValidationException("Invalid Version");
54 }
55 }
56
57
58
59
60
61
62 protected void validateId(Assertion assertion) throws ValidationException {
63 if (DatatypeHelper.isEmpty(assertion.getID())) {
64 throw new ValidationException("ID not present");
65 }
66 }
67
68
69
70
71
72
73 protected void validateIssuer(Assertion assertion) throws ValidationException {
74 if (DatatypeHelper.isEmpty(assertion.getIssuer())) {
75 throw new ValidationException("Issuer not present");
76 }
77 }
78
79
80
81
82
83
84 protected void validateIssueInstant(Assertion assertion) throws ValidationException {
85 if (assertion.getIssueInstant() == null) {
86 throw new ValidationException("IssueInstant not present");
87 }
88 }
89
90
91
92
93
94
95 protected void validateStatements(Assertion assertion) throws ValidationException {
96 List <Statement> list = assertion.getStatements();
97 if (list == null || list.size() == 0) {
98 throw new ValidationException("No Statements present");
99 }
100 }
101 }