View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.config.security;
19  
20  import org.opensaml.saml2.metadata.provider.MetadataProvider;
21  import org.opensaml.security.MetadataCredentialResolver;
22  import org.opensaml.security.MetadataCredentialResolverFactory;
23  import org.opensaml.xml.security.trust.ExplicitKeyTrustEngine;
24  import org.springframework.beans.factory.config.AbstractFactoryBean;
25  
26  /**
27   * Spring factory bean used to created {@link ExplicitKeyTrustEngine}s based on a metadata provider.
28   */
29  public class MetadataExplicitKeyTrustEngineFactoryBean extends AbstractFactoryBean {
30      
31      /** Metadata provider used to look up key information for peer entities. */
32      private MetadataProvider metadataProvider;
33  
34      /**
35       * Gets the metadata provider used to look up key information for peer entities.
36       * 
37       * @return metadata provider used to look up key information for peer entities
38       */
39      public MetadataProvider getMetadataProvider() {
40          return metadataProvider;
41      }
42  
43      /**
44       * Sets the metadata provider used to look up key information for peer entities.
45       * 
46       * @param provider metadata provider used to look up key information for peer entities
47       */
48      public void setMetadataProvider(MetadataProvider provider) {
49          metadataProvider = provider;
50      }
51  
52      /** {@inheritDoc} */
53      public Class getObjectType() {
54          return ExplicitKeyTrustEngine.class;
55      }
56      
57      /** {@inheritDoc} */
58      protected Object createInstance() throws Exception {
59          MetadataCredentialResolverFactory mcrFactory = MetadataCredentialResolverFactory.getFactory();
60          MetadataCredentialResolver credResolver = mcrFactory.getInstance(getMetadataProvider());
61          return new ExplicitKeyTrustEngine(credResolver);
62      }
63  }