de.smartics.util.test.security
Class KeyStoreTestHelper

Package class diagram package KeyStoreTestHelper
java.lang.Object
  extended by de.smartics.util.test.security.KeyStoreTestHelper

public final class KeyStoreTestHelper
     
     
extends Object

Helper to read a key store and make its keys and certificates easily accessible.

Author:
Robert Reiner

Method Summary
static KeyStoreTestHelper createFromClassPath(Class<?> referenceType, String name, String type, char[] password)
          Creates an instance of the key store helper read from the class path.
static KeyStoreTestHelper createFromClassPath(ClassLoader classLoader, String name, String type, char[] password)
          Creates an instance of the key store helper read from the class path.
static KeyStoreTestHelper createFromClassPathRelative(Class<?> referenceType, String relativeName, String type, char[] password)
          Creates an instance of the key store helper read from the class path.
static KeyStoreTestHelper createFromStream(InputStream input, String type, char[] password)
          Creates an instance of the key store helper read from the class path.
 KeyStore getKeyStore()
          Returns the test key store.
 Certificate readCertificate(String alias)
          Reads the certificate from the key store.
 PrivateKey readPrivateKey(String alias, char[] password)
          Reads the private key from the key store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getKeyStore

public KeyStore getKeyStore()
Returns the test key store.

Returns:
the test key store.

createFromClassPath

public static KeyStoreTestHelper createFromClassPath(ClassLoader classLoader,
                                                     String name,
                                                     String type,
                                                     char[] password)
                                              throws IllegalArgumentException
Creates an instance of the key store helper read from the class path.

Parameters:
classLoader - the class loader to locate the key store specified by name.
name - the name of the key store to be read from the class path.
type - the type of the key store to be read.
password - the password to access the key store.
Returns:
the created instance.
Throws:
IllegalArgumentException - if the key store cannot be read with the information given.

createFromClassPath

public static KeyStoreTestHelper createFromClassPath(Class<?> referenceType,
                                                     String name,
                                                     String type,
                                                     char[] password)
                                              throws IllegalArgumentException
Creates an instance of the key store helper read from the class path.

Parameters:
referenceType - the type whose class loader is to be used to locate the key store specified by name.
name - the name of the key store to be read from the class path.
type - the type of the key store to be read.
password - the password to access the key store.
Returns:
the created instance.
Throws:
IllegalArgumentException - if the key store cannot be read with the information given.

createFromClassPathRelative

public static KeyStoreTestHelper createFromClassPathRelative(Class<?> referenceType,
                                                             String relativeName,
                                                             String type,
                                                             char[] password)
                                                      throws IllegalArgumentException
Creates an instance of the key store helper read from the class path.

Parameters:
referenceType - the type whose class loader is to be used to locate the key store specified by relativeName.
relativeName - the relative name of the key store to be read from the class path.
type - the type of the key store to be read.
password - the password to access the key store.
Returns:
the created instance.
Throws:
IllegalArgumentException - if the key store cannot be read with the information given.

createFromStream

public static KeyStoreTestHelper createFromStream(InputStream input,
                                                  String type,
                                                  char[] password)
                                           throws IllegalArgumentException
Creates an instance of the key store helper read from the class path.

Parameters:
input - the stream to read the key store from.
type - the type of the key store to be read.
password - the password to access the key store.
Returns:
the created instance.
Throws:
IllegalArgumentException - if the key store cannot be read with the information given.

readPrivateKey

public PrivateKey readPrivateKey(String alias,
                                 char[] password)
                          throws IllegalArgumentException
Reads the private key from the key store.

Parameters:
alias - the alias of the private key.
password - the password to access the private key.
Returns:
the private key from the key store.
Throws:
IllegalArgumentException - if the information is not sufficient to access the private key.

readCertificate

public Certificate readCertificate(String alias)
                            throws IllegalArgumentException
Reads the certificate from the key store.

Parameters:
alias - the alias of the certificate.
Returns:
the certificate from the key store.
Throws:
IllegalArgumentException - if the certificate cannot be read from the key store.


Copyright © 2008-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.