View Javadoc

1   /*
2    * Copyright 2011 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 edu.internet2.middleware.shibboleth.common.config.security;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.opensaml.xml.security.x509.PKIXValidationOptions;
22  import org.opensaml.xml.util.DatatypeHelper;
23  import org.opensaml.xml.util.XMLHelper;
24  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
25  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
26  import org.w3c.dom.Attr;
27  import org.w3c.dom.Element;
28  
29  /** Spring bean definition parser for {urn:mace:shibboleth:2.0:security}PKIXValidationOptions elements. */
30  public class PKIXValidationOptionsBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
31      
32      /** Element name. */
33      public static final QName ELEMENT_NAME = new QName(SecurityNamespaceHandler.NAMESPACE, "ValidationOptions");
34      
35      /** Schema type. */
36      public static final QName SCHEMA_TYPE = new QName(SecurityNamespaceHandler.NAMESPACE, "ValidationOptionsType");
37      
38      /** {@inheritDoc} */
39      protected Class getBeanClass(Element element) {
40          return PKIXValidationOptions.class;
41      }
42      
43      /** {@inheritDoc} */
44      protected boolean shouldGenerateId() {
45          return true;
46      }
47      
48      /** {@inheritDoc} */
49      protected void doParse(Element element, BeanDefinitionBuilder builder) {
50          if (element.hasAttributeNS(null, "processEmptyCRLs")) {
51              Attr attr = element.getAttributeNodeNS(null, "processEmptyCRLs");
52              builder.addPropertyValue("processEmptyCRLs", XMLHelper.getAttributeValueAsBoolean(attr));
53          }
54          
55          if (element.hasAttributeNS(null, "processExpiredCRLs")) {
56              Attr attr = element.getAttributeNodeNS(null, "processExpiredCRLs");
57              builder.addPropertyValue("processExpiredCRLs", XMLHelper.getAttributeValueAsBoolean(attr));
58          }
59          
60          if (element.hasAttributeNS(null, "processCredentialCRLs")) {
61              Attr attr = element.getAttributeNodeNS(null, "processCredentialCRLs");
62              builder.addPropertyValue("processCredentialCRLs", XMLHelper.getAttributeValueAsBoolean(attr));
63          }
64          
65          if (element.hasAttributeNS(null, "defaultVerificationDepth")) {
66              Integer depth = new Integer(DatatypeHelper.safeTrim(element.getAttributeNS(null, "defaultVerificationDepth")));
67              builder.addPropertyValue("defaultVerificationDepth", depth);
68          }
69          
70      }
71  
72  }