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