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.springframework.beans.factory.support.BeanDefinitionBuilder;
28  import org.springframework.beans.factory.xml.ParserContext;
29  import org.w3c.dom.Element;
30  
31  import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.AttributeRule;
32  import edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils;
33  
34  /**
35   * Spring bean definition parser to configure an {@link AttributeRule}.
36   */
37  public class AttributeRuleBeanDefinitionParser extends BaseFilterBeanDefinitionParser {
38  
39      /** Element name. */
40      public static final QName ELEMENT_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRule");
41  
42      /** Schema type name. */
43      public static final QName TYPE_NAME = new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRuleType");
44  
45      /** {@inheritDoc} */
46      protected Class getBeanClass(Element arg0) {
47          return AttributeRule.class;
48      }
49  
50      /** {@inheritDoc} */
51      protected void doParse(Element configElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
52          super.doParse(configElement, parserContext, builder);
53  
54          builder.addConstructorArgValue(DatatypeHelper.safeTrimOrNullString(configElement.getAttributeNS(null,
55                  "attributeID")));
56  
57          Map<QName, List<Element>> children = XMLHelper.getChildElements(configElement);
58  
59          List<Element> permitValueRule = children.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE,
60                  "PermitValueRule"));
61          if (permitValueRule != null && !permitValueRule.isEmpty()) {
62              builder.addPropertyValue("permitValueRule", SpringConfigurationUtils.parseInnerCustomElement(
63                      permitValueRule.get(0), parserContext));
64          }
65  
66          List<Element> permitValueRuleRef = children.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE,
67                  "PermitValueRuleReference"));
68          if (permitValueRuleRef != null && !permitValueRuleRef.isEmpty()) {
69              String reference = getAbsoluteReference(configElement, "PermitValueRule", permitValueRuleRef.get(0)
70                      .getTextContent());
71              builder.addPropertyReference("permitValueRule", reference);
72          }
73  
74          List<Element> denyValueRule = children
75                  .get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "DenyValueRule"));
76          if (denyValueRule != null && !denyValueRule.isEmpty()) {
77              builder.addPropertyValue("denyValueRule", SpringConfigurationUtils.parseInnerCustomElement(denyValueRule
78                      .get(0), parserContext));
79          }
80  
81          List<Element> denyValueRuleRef = children.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE,
82                  "DenyValueRuleReference"));
83          if (denyValueRuleRef != null && !denyValueRuleRef.isEmpty()) {
84              String reference = getAbsoluteReference(configElement, "DenyValueRuleReference", denyValueRuleRef.get(0)
85                      .getTextContent());
86              builder.addPropertyReference("denyValueRule", reference);
87          }
88      }
89  }