View Javadoc

1   /*
2    * Copyright [2007] [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.metadata;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.opensaml.saml2.metadata.provider.HTTPMetadataProvider;
22  import org.opensaml.xml.util.DatatypeHelper;
23  import org.opensaml.xml.util.XMLHelper;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
27  import org.springframework.beans.factory.xml.ParserContext;
28  import org.w3c.dom.Element;
29  
30  /**
31   * Spring bean definition parser for Shibboleth file backed url metadata provider definition.
32   */
33  public class HTTPMetadataProviderBeanDefinitionParser extends BaseMetadataProviderBeanDefinitionParser {
34  
35      /** Schema type name. */
36      public static final QName TYPE_NAME = new QName(MetadataNamespaceHandler.NAMESPACE, "HTTPMetadataProvider");
37  
38      /** Class logger. */
39      private Logger log = LoggerFactory.getLogger(HTTPMetadataProviderBeanDefinitionParser.class);
40  
41      /** {@inheritDoc} */
42      protected Class getBeanClass(Element element) {
43          return HTTPMetadataProvider.class;
44      }
45  
46      /** {@inheritDoc} */
47      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
48          builder.setInitMethodName("initialize");
49  
50          super.doParse(element, parserContext, builder);
51  
52          builder.addPropertyReference("parserPool", "shibboleth.ParserPool");
53  
54          String metadataURL = element.getAttributeNS(null, "metadataURL");
55          builder.addConstructorArgValue(metadataURL);
56  
57          if (element.hasAttributeNS(null, "requestTimeout")) {
58              builder.addConstructorArgValue(Integer.parseInt(DatatypeHelper.safeTrim(element.getAttributeNS(null,
59                      "requestTimeout"))));
60          } else {
61              builder.addConstructorArgValue(10000);
62          }
63  
64          if (element.hasAttributeNS(null, "cacheDuration")) {
65              builder.addPropertyValue("maxCacheDuration", Integer.parseInt(DatatypeHelper.safeTrim(element
66                      .getAttributeNS(null, "cacheDuration"))));
67          } else {
68              builder.addPropertyValue("maxCacheDuration", 2880);
69          }
70  
71          if (element.hasAttributeNS(null, "maintainExpiredMetadata")) {
72              builder.addPropertyValue("maintainExpiredMetadata", XMLHelper.getAttributeValueAsBoolean(element
73                      .getAttributeNodeNS(null, "maintainExpiredMetadata")));
74          } else {
75              builder.addPropertyValue("maintainExpiredMetadata", false);
76          }
77  
78          // log.warn("Use of the HTTPMetadataProvider is deprecated.  Please use the ResourceBackedMetadataProvider with a HttpResource");
79      }
80  }