Class PasswordAdapter
java.lang.Object
com.sun.enterprise.security.store.PasswordAdapter
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 -
Constructor Summary
ConstructorsConstructorDescriptionPasswordAdapter(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
Modifier and TypeMethodDescriptionbooleanaliasExists(String alias) See if the given alias existsvoidchangePassword(char[] newMasterPassword) Changes the keystore password, including the encoding of the keys within it.Return the aliases from the keystore.getPasswordForAlias(String alias) This methods returns password String for a given alias and SMP.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.voidWrites the keystore to disk
-
Field Details
-
PASSWORD_ALIAS_KEYSTORE
- See Also:
-
-
Constructor Details
-
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:
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 Details
-
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
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
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-keyBytes-- Throws:
CertificateExceptionIOExceptionKeyStoreExceptionNoSuchAlgorithmExceptionUnrecoverableKeyException
-
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:
KeyStoreExceptionIOExceptionNoSuchAlgorithmExceptionCertificateExceptionUnrecoverableKeyException
-