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