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.common.SAMLVersion;
24 import org.opensaml.saml2.core.RequestAbstractType;
25 import org.opensaml.xml.util.DatatypeHelper;
26 import org.opensaml.xml.validation.ValidationException;
27 import org.opensaml.xml.validation.Validator;
28
29
30
31
32
33
34 public abstract class RequestAbstractTypeSchemaValidator<RequestType extends RequestAbstractType> implements
35 Validator<RequestType> {
36
37
38
39
40 public RequestAbstractTypeSchemaValidator() {
41 }
42
43
44 public void validate(RequestType request) throws ValidationException {
45 validateID(request);
46 validateVersion(request);
47 validateIssueInstant(request);
48
49 }
50
51
52
53
54
55
56
57 protected void validateID(RequestAbstractType request) throws ValidationException {
58 if (DatatypeHelper.isEmpty(request.getID())) {
59 throw new ValidationException("ID attribute must not be empty");
60 }
61 }
62
63
64
65
66
67
68
69 protected void validateVersion(RequestAbstractType request) throws ValidationException {
70 if (request.getVersion() == null) {
71 throw new ValidationException("Version attribute must not be null");
72 }
73 if (request.getVersion().toString() != SAMLVersion.VERSION_20.toString()) {
74 throw new ValidationException("Wrong SAML Version");
75 }
76 }
77
78
79
80
81
82
83
84 protected void validateIssueInstant(RequestAbstractType request) throws ValidationException {
85 if (request.getIssueInstant() == null) {
86 throw new ValidationException("IssueInstant attribute must not be null");
87 }
88 }
89 }