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;
18  
19  import java.util.List;
20  
21  import org.opensaml.DefaultBootstrap;
22  import org.opensaml.util.resource.Resource;
23  import org.opensaml.xml.XMLConfigurator;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.beans.factory.InitializingBean;
27  
28  /**
29   * A simple bean that may be used with Spring to initialize the OpenSAML library.
30   */
31  public class OpensamlConfigBean implements InitializingBean {
32      
33      /** Class logger. */
34      private final Logger log = LoggerFactory.getLogger(OpensamlConfigBean.class);
35      
36      /** OpenSAML configuration resources. */
37      private List<Resource> configResources;
38      
39      /**
40       * Constructor.
41       *
42       * @param configs OpenSAML configuration resources
43       */
44      public OpensamlConfigBean(List<Resource> configs){
45          configResources = configs;
46      }
47  
48      /** {@inheritDoc} */
49      public void afterPropertiesSet() throws Exception {
50          DefaultBootstrap.bootstrap();
51          
52          if(configResources != null && !configResources.isEmpty()){
53              XMLConfigurator configurator = new XMLConfigurator();
54              for(Resource config : configResources){
55                  try{
56                      log.debug("Loading OpenSAML configuration file: {}", config.getLocation());
57                      configurator.load(config.getInputStream());
58                  }catch(Exception e){
59                      log.error("Unable to load OpenSAML configuration file: " + config.getLocation());
60                  }
61              }
62          }
63      }
64  }