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.saml;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.opensaml.xml.util.DatatypeHelper;
23  import org.opensaml.xml.util.XMLHelper;
24  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
25  import org.springframework.beans.factory.xml.ParserContext;
26  import org.w3c.dom.Element;
27  
28  import edu.internet2.middleware.shibboleth.common.relyingparty.provider.CryptoOperationRequirementLevel;
29  
30  /**
31   * Base Spring configuration parser for SAML 2 profile configurations.
32   */
33  public abstract class AbstractSAML2ProfileConfigurationBeanDefinitionParser extends
34          AbstractSAMLProfileConfigurationBeanDefinitionParser {
35  
36      /** {@inheritDoc} */
37      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
38          super.doParse(element, parserContext, builder);
39  
40          List<Element> proxyAudiences = XMLHelper.getChildElementsByTagNameNS(element,
41                  SAMLRelyingPartyNamespaceHandler.NAMESPACE, "ProxyAudience");
42          if (proxyAudiences != null && proxyAudiences.size() > 0) {
43              ArrayList<String> audiences = new ArrayList<String>();
44              for (Element proxyAudience : proxyAudiences) {
45                  audiences.add(DatatypeHelper.safeTrimOrNullString(proxyAudience.getTextContent()));
46              }
47  
48              builder.addPropertyValue("proxyAudiences", audiences);
49          }
50  
51          builder.addPropertyReference("attributeAuthority", DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(
52                  null, "attributeAuthority")));
53  
54          if (element.hasAttributeNS(null, "encryptNameIds")) {
55              builder.addPropertyValue("encryptNameIds", CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(
56                      null, "encryptNameIds")));
57          } else {
58              builder.addPropertyValue("encryptNameIds", CryptoOperationRequirementLevel.never);
59          }
60  
61          if (element.hasAttributeNS(null, "encryptAssertions")) {
62              builder.addPropertyValue("encryptAssertions", CryptoOperationRequirementLevel.valueOf(element
63                      .getAttributeNS(null, "encryptAssertions")));
64          } else {
65              builder.addPropertyValue("encryptAssertions", CryptoOperationRequirementLevel.conditional);
66          }
67  
68          if (element.hasAttributeNS(null, "assertionProxyCount")) {
69              builder.addPropertyValue("assertionProxyCount", Integer.parseInt(DatatypeHelper
70                      .safeTrimOrNullString(element.getAttributeNS(null, "assertionProxyCount"))));
71          } else {
72              builder.addPropertyValue("assertionProxyCount", 0);
73          }
74      }
75  }