1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
37
38 public class RelyingPartyGroupBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
39
40
41 public static final QName ELEMENT_NAME = new QName(RelyingPartyNamespaceHandler.NAMESPACE, "RelyingPartyGroup");
42
43
44 protected Class getBeanClass(Element element) {
45 return RelyingPartyGroup.class;
46 }
47
48
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
67
68
69
70
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
92
93
94
95
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
114 protected boolean shouldGenerateId() {
115 return true;
116 }
117 }