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 String
PASSWORD_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 boolean
aliasExists(String alias)
See if the given alias existsvoid
changePassword(char[] newMasterPassword)
Changes the keystore password, including the encoding of the keys within it.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 keystorevoid
setPasswordForAlias(String alias, byte[] keyBytes)
This methods set alias, secretKey into JCEKS keystore.void
writeStore()
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, 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 namesmp
- 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
-
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:
- 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:
KeyStoreException
IOException
NoSuchAlgorithmException
CertificateException
UnrecoverableKeyException
-
-