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  package org.opensaml.saml2.core.validator;
18  
19  import org.opensaml.saml2.core.ManageNameIDRequest;
20  import org.opensaml.xml.validation.ValidationException;
21  
22  /**
23   * Checks {@link org.opensaml.saml2.core.ManageNameIDRequest} for Schema compliance.
24   */
25  public class ManageNameIDRequestSchemaValidator extends RequestAbstractTypeSchemaValidator<ManageNameIDRequest> {
26  
27      /**
28       * Constructor
29       *
30       */
31      public ManageNameIDRequestSchemaValidator() {
32          super();
33      }
34  
35      /** {@inheritDoc} */
36      public void validate(ManageNameIDRequest request) throws ValidationException {
37          super.validate(request);
38          validateNameID(request);
39          validateNewIDAndTerminate(request);
40      }
41  
42      /**
43       * Validates NameID/EncryptedID child element
44       * 
45       * @param request
46       * @throws ValidationException 
47       */
48      protected void validateNameID(ManageNameIDRequest request) throws ValidationException {
49          int idCount = 0;
50          
51          if (request.getNameID() != null) {
52              idCount++;
53          }
54          if (request.getEncryptedID() != null) {
55              idCount++;
56          }
57          
58          if (idCount != 1) {
59              throw new ValidationException("ManageNameIDRequest must contain exactly one of: NameID, EncryptedID");
60          }
61      }
62      
63      /**
64       * Validates NewID/NewEncryptedID child element
65       * 
66       * @param request
67       * @throws ValidationException 
68       */
69      protected void validateNewIDAndTerminate(ManageNameIDRequest request) throws ValidationException {
70          int count = 0;
71          
72          if (request.getNewID() != null) {
73              count++;
74          }
75          if (request.getNewEncryptedID() != null) {
76              count++;
77          }
78          if (request.getTerminate() != null) {
79              count++;
80          }
81          
82          if (count != 1) {
83              throw new ValidationException("ManageNameIDRequest must contain exactly one of: NewID, NewEncryptedID, Terminate");
84          }
85      }
86      
87  }