View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.security.saml.ext;
21  
22  import java.io.InputStream;
23  
24  import org.opensaml.Configuration;
25  import org.opensaml.DefaultBootstrap;
26  import org.opensaml.xml.ConfigurationException;
27  import org.opensaml.xml.XMLConfigurator;
28  
29  /**
30   * This class intializes the Opensaml library. It is necessary to override DefaultBootstrap
31   * to avoid instantiating Velocity, which we do not need in WSS4J.
32   */
33  public class OpenSAMLBootstrap extends DefaultBootstrap {
34      
35      /** List of default XMLTooling configuration files. */
36      private static String[] xmlToolingConfigs = { 
37          "/default-config.xml", 
38          "/schema-config.xml", 
39          "/signature-config.xml",
40          "/signature-validation-config.xml", 
41          "/encryption-config.xml", 
42          "/encryption-validation-config.xml",
43          "/soap11-config.xml", 
44          "/wsfed11-protocol-config.xml",
45          "/saml1-assertion-config.xml", 
46          "/saml1-protocol-config.xml",
47          "/saml1-core-validation-config.xml", 
48          "/saml2-assertion-config.xml", 
49          "/saml2-protocol-config.xml",
50          "/saml2-core-validation-config.xml", 
51          "/saml1-metadata-config.xml", 
52          "/saml2-metadata-config.xml",
53          "/saml2-metadata-validation-config.xml", 
54          "/saml2-metadata-attr-config.xml",
55          "/saml2-metadata-idp-discovery-config.xml",
56          "/saml2-metadata-ui-config.xml",
57          "/saml2-protocol-thirdparty-config.xml",
58          "/saml2-metadata-query-config.xml", 
59          "/saml2-assertion-delegation-restriction-config.xml",    
60          "/saml2-ecp-config.xml",
61          "/saml2-xacml2-profile.xml",
62          "/xacml10-saml2-profile-config.xml",
63          "/xacml11-saml2-profile-config.xml",
64          "/xacml20-context-config.xml",
65          "/xacml20-policy-config.xml",
66          "/xacml2-saml2-profile-config.xml",
67          "/xacml3-saml2-profile-config.xml",    
68          "/wsaddressing-config.xml",
69          "/wssecurity-config.xml",
70      };
71      
72      /**
73       * Initializes the OpenSAML library, loading default configurations.
74       * 
75       * @throws ConfigurationException thrown if there is a problem initializing the OpenSAML library
76       */
77      public static synchronized void bootstrap() throws ConfigurationException {
78          initializeXMLSecurity();
79  
80          initializeXMLTooling(xmlToolingConfigs);
81  
82          initializeArtifactBuilderFactories();
83  
84          initializeGlobalSecurityConfiguration();
85          
86          initializeParserPool();
87      }
88  
89      
90      protected static void initializeXMLTooling(String[] providerConfigs) throws ConfigurationException {
91          XMLConfigurator configurator = new XMLConfigurator();
92          for (String config : providerConfigs) {
93              //most are found in the Configuration.class classloader
94              InputStream ins = Configuration.class.getResourceAsStream(config);
95              if (ins == null) {
96                  //some are from us
97                  ins = OpenSAMLBootstrap.class.getResourceAsStream(config);
98              }
99              configurator.load(ins);
100         }
101     }
102 }