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.relyingparty;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.opensaml.xml.util.XMLHelper;
25  import org.springframework.beans.factory.config.RuntimeBeanReference;
26  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
27  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
28  import org.springframework.beans.factory.xml.ParserContext;
29  import org.w3c.dom.Element;
30  
31  import edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils;
32  import edu.internet2.middleware.shibboleth.common.config.metadata.MetadataNamespaceHandler;
33  import edu.internet2.middleware.shibboleth.common.config.security.SecurityNamespaceHandler;
34  
35  /**
36   * Spring bean definition parser for relying party group configurations.
37   */
38  public class RelyingPartyGroupBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
39  
40      /** Element name. */
41      public static final QName ELEMENT_NAME = new QName(RelyingPartyNamespaceHandler.NAMESPACE, "RelyingPartyGroup");
42  
43      /** {@inheritDoc} */
44      protected Class getBeanClass(Element element) {
45          return RelyingPartyGroup.class;
46      }
47  
48      /** {@inheritDoc} */
49      protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) {
50          Map<QName, List<Element>> configChildren = XMLHelper.getChildElements(config);
51  
52          List<Element> mds = configChildren.get(new QName(MetadataNamespaceHandler.NAMESPACE, "MetadataProvider"));
53          if (mds != null && mds.size() > 0) {
54              Element mdConfigElem = mds.get(0);
55              SpringConfigurationUtils.parseCustomElement(mdConfigElem, parserContext);
56              builder.addPropertyValue("metadataProvider", new RuntimeBeanReference(mdConfigElem.getAttributeNS(null,
57                      "id")));
58          }
59  
60          parseRelyingPartyConfiguration(configChildren, builder, parserContext);
61  
62          parseSecurityConfiguration(configChildren, builder, parserContext);
63      }
64  
65      /**
66       * Parses the relying party related configuration elements.
67       * 
68       * @param configChildren relying party group children
69       * @param builder bean definition builder
70       * @param parserContext current parsing context
71       */
72      protected void parseRelyingPartyConfiguration(Map<QName, List<Element>> configChildren,
73              BeanDefinitionBuilder builder, ParserContext parserContext) {
74          List<Element> anonRP = configChildren.get(RelyingPartyConfigurationBeanDefinitionParser.ANON_RP_ELEMENT_NAME);
75          if (anonRP != null && anonRP.size() > 0) {
76              builder.addPropertyValue("anonymousRP", SpringConfigurationUtils.parseInnerCustomElement(anonRP.get(0),
77                      parserContext));
78          }
79  
80          List<Element> defaultRP = configChildren
81                  .get(RelyingPartyConfigurationBeanDefinitionParser.DEFAULT_RP_ELEMENT_NAME);
82          builder.addPropertyValue("defaultRP", SpringConfigurationUtils.parseInnerCustomElement(defaultRP.get(0),
83                  parserContext));
84  
85          List<Element> rps = configChildren.get(RelyingPartyConfigurationBeanDefinitionParser.RP_ELEMENT_NAME);
86          builder.addPropertyValue("relyingParties", SpringConfigurationUtils
87                  .parseInnerCustomElements(rps, parserContext));
88      }
89  
90      /**
91       * Parses the security related configuration elements.
92       * 
93       * @param configChildren relying party group children
94       * @param builder bean definition builder
95       * @param parserContext current parsing context
96       */
97      protected void parseSecurityConfiguration(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder,
98              ParserContext parserContext) {
99  
100         List<Element> creds = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Credential"));
101         builder.addPropertyValue("credentials", SpringConfigurationUtils
102                         .parseInnerCustomElements(creds, parserContext));
103 
104         List<Element> engines = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "TrustEngine"));
105         builder.addPropertyValue("trustEngines", SpringConfigurationUtils.parseInnerCustomElements(engines,
106                 parserContext));
107 
108         List<Element> secPols = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "SecurityPolicy"));
109         builder.addPropertyValue("securityPolicies", SpringConfigurationUtils.parseInnerCustomElements(secPols,
110                 parserContext));
111     }
112 
113     /** {@inheritDoc} */
114     protected boolean shouldGenerateId() {
115         return true;
116     }
117 }