com.sun.enterprise.security.store
Class PasswordAdapter

java.lang.Object
  extended by com.sun.enterprise.security.store.PasswordAdapter

public final class PasswordAdapter
extends Object

This class implements an adapter for password manipulation a JCEKS. Note that although it uses locks ('synchronized'), it tends to be created anew with each use, an inefficient and potentially problematic use that could create more than one instance accessing the same keystore at a time.


Field Summary
static String PASSWORD_ALIAS_KEYSTORE
           
 
Constructor Summary
PasswordAdapter(char[] masterPassword)
          Construct a PasswordAdapter with given Shared Master Password, SMP using the default keyfile (domain-passwords.jceks)
PasswordAdapter(String keyStoreFileName, char[] masterPassword)
          Construct a PasswordAdapter with given Shared Master Password, SMP.
 
Method Summary
 boolean aliasExists(String alias)
          See if the given alias exists
 void changePassword(char[] newMasterPassword)
          Changes the keystore password, including the encoding of the keys within it.
 byte[] decrypt(byte[] encrypted, String algorithm)
           
 Enumeration<String> getAliases()
          Return the aliases from the keystore.
 String getPasswordForAlias(String alias)
          This methods returns password String for a given alias and SMP.
 SecretKey getPasswordSecretKeyForAlias(String alias)
          This methods returns password SecretKey for a given alias and SMP.
 void removeAlias(String alias)
          Remove an alias from the keystore
 void setPasswordForAlias(String alias, byte[] keyBytes)
          This methods set alias, secretKey into JCEKS keystore.
 void writeStore()
          Writes the keystore to disk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSWORD_ALIAS_KEYSTORE

public static final String PASSWORD_ALIAS_KEYSTORE
See Also:
Constant Field Values
Constructor Detail

PasswordAdapter

public PasswordAdapter(char[] masterPassword)
                throws CertificateException,
                       IOException,
                       KeyStoreException,
                       NoSuchAlgorithmException
Construct a PasswordAdapter with given Shared Master Password, SMP using the default keyfile (domain-passwords.jceks)

Parameters:
smp - master password
Throws:
CertificateException
IOException
KeyStoreException
NoSuchAlgorithmException

PasswordAdapter

public PasswordAdapter(String keyStoreFileName,
                       char[] masterPassword)
                throws CertificateException,
                       IOException,
                       KeyStoreException,
                       NoSuchAlgorithmException
Construct a PasswordAdapter with given Shared Master Password, SMP.

Parameters:
keyfileName - the jceks key file name
smp - master password
Throws:
CertificateException
IOException
KeyStoreException
NoSuchAlgorithmException
Method Detail

getPasswordForAlias

public String getPasswordForAlias(String alias)
                           throws KeyStoreException,
                                  NoSuchAlgorithmException,
                                  UnrecoverableKeyException
This methods returns password String for a given alias and SMP.

Parameters:
alias -
Returns:
corresponding password or null if the alias does not exist.
Throws:
KeyStoreException
NoSuchAlgorithmException
UnrecoverableKeyException

getPasswordSecretKeyForAlias

public SecretKey getPasswordSecretKeyForAlias(String alias)
                                       throws KeyStoreException,
                                              NoSuchAlgorithmException,
                                              UnrecoverableKeyException
This methods returns password SecretKey for a given alias and SMP.

Parameters:
alias -
Returns:
corresponding password SecretKey or null if the alias does not exist.
Throws:
KeyStoreException
NoSuchAlgorithmException
UnrecoverableKeyException

aliasExists

public boolean aliasExists(String alias)
                    throws KeyStoreException
See if the given alias exists

Parameters:
alias - the alias name
Returns:
true if the alias exists in the keystore
Throws:
KeyStoreException

removeAlias

public void removeAlias(String alias)
                 throws KeyStoreException,
                        IOException,
                        NoSuchAlgorithmException,
                        CertificateException,
                        UnrecoverableKeyException
Remove an alias from the keystore

Parameters:
alias - The name of the alias to remove
Throws:
KeyStoreException
IOException
NoSuchAlgorithmException
CertificateException
UnrecoverableKeyException

getAliases

public Enumeration<String> getAliases()
                               throws KeyStoreException
Return the aliases from the keystore.

Returns:
An enumeration containing all the aliases in the keystore.
Throws:
KeyStoreException

writeStore

public void writeStore()
                throws KeyStoreException,
                       IOException,
                       NoSuchAlgorithmException,
                       CertificateException,
                       UnrecoverableKeyException
Writes the keystore to disk

Throws:
KeyStoreException
IOException
NoSuchAlgorithmException
CertificateException
UnrecoverableKeyException

setPasswordForAlias

public void setPasswordForAlias(String alias,
                                byte[] keyBytes)
                         throws CertificateException,
                                IOException,
                                KeyStoreException,
                                NoSuchAlgorithmException,
                                UnrecoverableKeyException
This methods set alias, secretKey into JCEKS keystore.

Parameters:
alias -
secretKey -
Throws:
CertificateException
IOException
KeyStoreException
NoSuchAlgorithmException
UnrecoverableKeyException

changePassword

public void changePassword(char[] newMasterPassword)
                    throws KeyStoreException,
                           IOException,
                           NoSuchAlgorithmException,
                           CertificateException,
                           UnrecoverableKeyException
Changes the keystore password, including the encoding of the keys within it.

There are several error conditions that could occur:

For these reasons, make a new KeyStore and write it, then swap it with the old one.

Parameters:
newpassword - the new keystore password
Throws:
KeyStoreException
IOException
NoSuchAlgorithmException
CertificateException
UnrecoverableKeyException

decrypt

public byte[] decrypt(byte[] encrypted,
                      String algorithm)
               throws NoSuchAlgorithmException,
                      IOException,
                      NoSuchPaddingException,
                      InvalidKeyException,
                      InvalidAlgorithmParameterException,
                      IllegalBlockSizeException,
                      BadPaddingException
Throws:
NoSuchAlgorithmException
IOException
NoSuchPaddingException
InvalidKeyException
InvalidAlgorithmParameterException
IllegalBlockSizeException
BadPaddingException


Copyright © 2012 GlassFish Community. All Rights Reserved.