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.io.FileInputStream;
20  import java.io.IOException;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.springframework.beans.FatalBeanException;
25  
26  /**
27   * Spring bean definition parser for filesytem-based credential configuration elements.
28   */
29  public class FilesystemBasicCredentialBeanDefinitionParser extends AbstractBasicCredentialBeanDefinitionParser {
30  
31      /** Schema type. */
32      public static final QName SCHEMA_TYPE = new QName(SecurityNamespaceHandler.NAMESPACE, "BasicFilesystem");
33  
34      /** {@inheritDoc} */
35      protected byte[] getEncodedPrivateKey(String keyConfigContent) {
36          try {
37              FileInputStream ins = new FileInputStream(keyConfigContent);
38              byte[] encoded = new byte[ins.available()];
39              ins.read(encoded);
40              return encoded;
41          } catch (IOException e) {
42              throw new FatalBeanException("Unable to read private key from file " + keyConfigContent, e);
43          }
44      }
45  
46      /** {@inheritDoc} */
47      protected byte[] getEncodedSecretKey(String keyConfigContent) {
48          try {
49              FileInputStream ins = new FileInputStream(keyConfigContent);
50              byte[] encoded = new byte[ins.available()];
51              ins.read(encoded);
52              return encoded;
53          } catch (IOException e) {
54              throw new FatalBeanException("Unable to read secret key from file " + keyConfigContent, e);
55          }
56      }
57  
58      /** {@inheritDoc} */
59      protected byte[] getEncodedPublicKey(String keyConfigContent) {
60          try {
61              FileInputStream ins = new FileInputStream(keyConfigContent);
62              byte[] encoded = new byte[ins.available()];
63              ins.read(encoded);
64              return encoded;
65          } catch (IOException e) {
66              throw new FatalBeanException("Unable to read public key from file " + keyConfigContent, e);
67          }
68      }
69      
70  }