View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /**
18   * 
19   */
20  package org.opensaml.saml1.core.validator;
21  
22  import org.opensaml.saml1.core.Assertion;
23  import org.opensaml.saml1.core.Condition;
24  import org.opensaml.saml1.core.Conditions;
25  import org.opensaml.saml1.core.DoNotCacheCondition;
26  import org.opensaml.xml.validation.ValidationException;
27  import org.opensaml.xml.validation.Validator;
28  
29  /**
30   * Spec validator for {@link org.opensaml.saml1.core.Assertion}
31   */
32  public class AssertionSpecValidator implements Validator<Assertion> {
33  
34      public void validate(Assertion assertion) throws ValidationException {
35          validateDoNotCache(assertion);
36      }
37      
38      protected void validateDoNotCache(Assertion assertion) throws ValidationException {
39          
40          if (assertion.getMinorVersion() == 0) {
41              Conditions conditions = assertion.getConditions();
42              if (conditions != null) {
43                  for (Condition condition : conditions.getConditions()) {
44                      if (condition instanceof DoNotCacheCondition) {
45                          throw new ValidationException("DoNotCacheCondition not valid in SAML1.0");
46                      }
47                  }
48              }
49          }
50      }
51  }