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 java.util.List;
20  
21  import org.opensaml.xml.util.DatatypeHelper;
22  import org.opensaml.xml.util.XMLHelper;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
26  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
27  import org.springframework.beans.factory.xml.ParserContext;
28  import org.w3c.dom.Element;
29  
30  import edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils;
31  
32  /** Base class for metadata provider configuration parser. */
33  public abstract class BaseMetadataProviderBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
34  
35      /** Class logger. */
36      private final Logger log = LoggerFactory.getLogger(BaseMetadataProviderBeanDefinitionParser.class);
37  
38      /** {@inheritDoc} */
39      protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) {
40          String id = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "id"));
41          log.debug("Parsing configuration for {} metadata provider with ID: {}", XMLHelper.getXSIType(config)
42                  .getLocalPart(), id);
43  
44          boolean requireValidMDBool = false;
45          if (config.hasAttributeNS(null, "requireValidMetadata")) {
46              requireValidMDBool = XMLHelper.getAttributeValueAsBoolean(config.getAttributeNodeNS(null,
47                      "requireValidMetadata"));
48          }
49          if (log.isDebugEnabled()) {
50              log.debug("Metadata provider {} requires valid metadata: {}", id, requireValidMDBool);
51          }
52          builder.addPropertyValue("requireValidMetadata", requireValidMDBool);
53  
54          List<Element> childElems = XMLHelper.getChildElementsByTagNameNS(config, MetadataNamespaceHandler.NAMESPACE,
55                  "MetadataFilter");
56          if (childElems.size() > 0) {
57              builder.addPropertyValue("metadataFilter", SpringConfigurationUtils.parseInnerCustomElement(
58                      (Element) childElems.get(0), parserContext));
59          }
60      }
61  }