Class PasswordAdapter
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description static StringPASSWORD_ALIAS_KEYSTORE
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaliasExists(String alias)See if the given alias existsvoidchangePassword(char[] newMasterPassword)Changes the keystore password, including the encoding of the keys within it.Enumeration<String>getAliases()Return the aliases from the keystore.StringgetPasswordForAlias(String alias)This methods returns password String for a given alias and SMP.SecretKeygetPasswordSecretKeyForAlias(String alias)This methods returns password SecretKey for a given alias and SMP.voidremoveAlias(String alias)Remove an alias from the keystorevoidsetPasswordForAlias(String alias, byte[] keyBytes)This methods set alias, secretKey into JCEKS keystore.voidwriteStore()Writes the keystore to disk
-
-
-
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, NoSuchAlgorithmExceptionConstruct a PasswordAdapter with given Shared Master Password, SMP using the default keyfile (domain-passwords.jceks)- Parameters:
smp- master password- Throws:
CertificateExceptionIOExceptionKeyStoreExceptionNoSuchAlgorithmException
-
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 namesmp- master password- Throws:
CertificateExceptionIOExceptionKeyStoreExceptionNoSuchAlgorithmException
-
-
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:
KeyStoreExceptionNoSuchAlgorithmExceptionUnrecoverableKeyException
-
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:
KeyStoreExceptionNoSuchAlgorithmExceptionUnrecoverableKeyException
-
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:
KeyStoreExceptionIOExceptionNoSuchAlgorithmExceptionCertificateExceptionUnrecoverableKeyException
-
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, UnrecoverableKeyExceptionWrites the keystore to disk
-
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:
CertificateExceptionIOExceptionKeyStoreExceptionNoSuchAlgorithmExceptionUnrecoverableKeyException
-
changePassword
public void changePassword(char[] newMasterPassword) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyExceptionChanges the keystore password, including the encoding of the keys within it.There are several error conditions that could occur:
- Problem extracting existing alias keys with new ones.
- Problem writing the keystore, including destroying it if an I/O problem occurs.
- Parameters:
newpassword- the new keystore password- Throws:
KeyStoreExceptionIOExceptionNoSuchAlgorithmExceptionCertificateExceptionUnrecoverableKeyException
-
-