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  
21  package org.opensaml.saml1.core.validator;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.opensaml.saml1.core.AuthorityBinding;
26  import org.opensaml.xml.util.DatatypeHelper;
27  import org.opensaml.xml.validation.ValidationException;
28  import org.opensaml.xml.validation.Validator;
29  
30  /**
31   * Checks {@link org.opensaml.saml1.core.AuthorityBinding} for Schema compliance.
32   */
33  public class AuthorityBindingSchemaValidator implements Validator<AuthorityBinding> {
34  
35      /** {@inheritDoc} */
36      public void validate(AuthorityBinding authorityBinding) throws ValidationException {
37          validateAuthorityKind(authorityBinding);
38          validateBinding(authorityBinding);
39          validateLocation(authorityBinding);
40      }
41      
42      /**
43       * Check that the AuthorityKind is valid
44       * @param authorityBinding
45       * @throws ValidationException
46       */
47      protected void validateAuthorityKind(AuthorityBinding authorityBinding) throws ValidationException {
48          //
49          // TODO may need to do more validation on the QName here - need to make sure
50          // that the prefix is valid - cases of 
51          // 1) no incoming XML validation was performed
52          // 2) validating parser that doesn't properly validate this QName value.
53          //
54          QName authorityKind = authorityBinding.getAuthorityKind();    
55          if (authorityKind == null) {
56               throw new ValidationException("No AuthorityKind attribute present");
57           }
58      }
59      
60      /**
61       * Check the location Attribute for validity
62       * @param authorityBinding
63       * @throws ValidationException
64       */
65      protected void validateLocation(AuthorityBinding authorityBinding) throws ValidationException {
66          if (DatatypeHelper.isEmpty(authorityBinding.getLocation())) {
67              throw new ValidationException("Location attribute not present or invalid ");
68          }
69      }
70  
71      /**
72       * Check the binding Attribute for validity
73       * @param authorityBinding
74       * @throws ValidationException
75       */
76      protected void validateBinding(AuthorityBinding authorityBinding) throws ValidationException {
77          if (DatatypeHelper.isEmpty(authorityBinding.getBinding())) {
78              throw new ValidationException("Binding attribute not present or invalid ");
79          }
80      }
81  }