View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.config.attribute.filtering;
19  
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.opensaml.xml.util.DatatypeHelper;
26  import org.opensaml.xml.util.XMLHelper;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.beans.factory.config.BeanDefinition;
30  import org.springframework.beans.factory.xml.BeanDefinitionParser;
31  import org.springframework.beans.factory.xml.ParserContext;
32  import org.w3c.dom.Element;
33  
34  import edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils;
35  
36  /**
37   * Spring bean definition parser for Shibboleth attribute filtering engine attribute filter policy.
38   */
39  public class AttributeFilterPolicyGroupBeanDefinitionParser implements BeanDefinitionParser {
40  
41      /** Element name. */
42      public static final QName ELEMENT_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE,
43              "AttributeFilterPolicyGroup");
44  
45      /** Schema type name. */
46      public static final QName TYPE_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE,
47              "AttributeFilterPolicyGroupType");
48  
49      /** Local name of the policy requirement element. */
50      public static final QName POLICY_REQUIREMENT_ELEMENT_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE,
51              "PolicyRequirement");
52  
53      /** Local name of the value filter element. */
54      public static final QName PERMIT_VALUE_ELEMENT_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE,
55              "PermitValue");
56  
57      /** Class logger. */
58      private final Logger log = LoggerFactory.getLogger(AttributeFilterPolicyGroupBeanDefinitionParser.class);
59  
60      /** {@inheritDoc} */
61      public BeanDefinition parse(Element config, ParserContext context) {
62          String policyId = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "id"));
63  
64          log.debug("Parsing attribute filter policy group {}", policyId);
65  
66          List<Element> children;
67          Map<QName, List<Element>> childrenMap = XMLHelper.getChildElements(config);
68  
69          children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PolicyRequirementRule"));
70          SpringConfigurationUtils.parseInnerCustomElements(children, context);
71  
72          children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRule"));
73          SpringConfigurationUtils.parseInnerCustomElements(children, context);
74  
75          children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PermitValueRule"));
76          SpringConfigurationUtils.parseInnerCustomElements(children, context);
77  
78          children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeFilterPolicy"));
79          SpringConfigurationUtils.parseInnerCustomElements(children, context);
80  
81          return null;
82      }
83  }