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.Conditions;
24 import org.opensaml.saml2.core.OneTimeUse;
25 import org.opensaml.saml2.core.ProxyRestriction;
26 import org.opensaml.xml.validation.ValidationException;
27 import org.opensaml.xml.validation.Validator;
28
29
30
31
32 public class ConditionsSpecValidator implements Validator<Conditions> {
33
34
35 public ConditionsSpecValidator() {
36
37 }
38
39
40 public void validate(Conditions conditions) throws ValidationException {
41 validateOneTimeUseCondition(conditions);
42 validateProxyRestrictionCondition(conditions);
43 }
44
45
46
47
48
49
50
51 protected void validateOneTimeUseCondition(Conditions conditions) throws ValidationException {
52 int oneTimeUseCount = 0;
53 for (int i = 0; i < conditions.getConditions().size(); i++) {
54 if (conditions.getConditions().get(i) instanceof OneTimeUse) {
55 oneTimeUseCount++;
56 }
57 }
58
59 if (oneTimeUseCount > 1) {
60 throw new ValidationException("At most one instance of OneTimeUse allowed");
61 }
62 }
63
64 protected void validateProxyRestrictionCondition(Conditions conditions) throws ValidationException {
65 int proxyRestrictionCount = 0;
66 for (int i = 0; i < conditions.getConditions().size(); i++) {
67 if (conditions.getConditions().get(i) instanceof ProxyRestriction) {
68 proxyRestrictionCount++;
69 }
70 }
71
72 if (proxyRestrictionCount > 1) {
73 throw new ValidationException("At most one instance of ProxyRestriction allowed");
74 }
75 }
76 }