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.security;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.opensaml.xml.security.credential.Credential;
23  import org.opensaml.xml.security.credential.StaticCredentialResolver;
24  import org.opensaml.xml.security.keyinfo.BasicProviderKeyInfoCredentialResolver;
25  import org.opensaml.xml.security.keyinfo.KeyInfoCredentialResolver;
26  import org.opensaml.xml.security.keyinfo.KeyInfoProvider;
27  import org.opensaml.xml.security.keyinfo.provider.DSAKeyValueProvider;
28  import org.opensaml.xml.security.keyinfo.provider.InlineX509DataProvider;
29  import org.opensaml.xml.security.keyinfo.provider.RSAKeyValueProvider;
30  import org.opensaml.xml.signature.impl.ExplicitKeySignatureTrustEngine;
31  import org.springframework.beans.factory.config.AbstractFactoryBean;
32  
33  /**
34   * Spring factory bean used to created {@link ExplicitKeySignatureTrustEngine}s based on a static credential resolver.
35   */
36  public class StaticExplicitKeySignatureTrustEngineFactoryBean extends AbstractFactoryBean {
37      
38      /** List of trusted credentials. */
39      private List<Credential> credentials;
40  
41      /**
42       * Gets the list of trusted credentials.
43       * 
44       * @return the list of trusted credentials
45       */
46      public List<Credential> getCredentials() {
47          return credentials;
48      }
49  
50      /**
51       * Sets the list of trusted credentials.
52       * 
53       * @param newCredentials the new list of trusted credentials
54       */
55      public void setCredentials(List<Credential> newCredentials) {
56          credentials = newCredentials;
57      }
58  
59      /** {@inheritDoc} */
60      public Class getObjectType() {
61          return ExplicitKeySignatureTrustEngine.class;
62      }
63      
64      /** {@inheritDoc} */
65      protected Object createInstance() throws Exception {
66          StaticCredentialResolver credResolver = new StaticCredentialResolver(getCredentials());
67          
68          List<KeyInfoProvider> keyInfoProviders = new ArrayList<KeyInfoProvider>();
69          keyInfoProviders.add(new DSAKeyValueProvider());
70          keyInfoProviders.add(new RSAKeyValueProvider());
71          keyInfoProviders.add(new InlineX509DataProvider());
72          KeyInfoCredentialResolver keyInfoCredResolver = new BasicProviderKeyInfoCredentialResolver(keyInfoProviders);
73          
74          return new ExplicitKeySignatureTrustEngine(credResolver, keyInfoCredResolver);
75      }
76  }