use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.
the class KeystoreManager method changeS1ASAliasPassword.
/**
* Changes the key password for the default cert whose alias is s1as. The assumption here is that the keystore password
* is not the same as the key password. This is due to the fact that the keystore password should first be changed
* followed next by the key password. The end result is that the keystore and s1as key both have the same passwords.
* This function will tolerate deletion of the s1as alias, but it will not tolerate changing the s1as key from something
* other than the database password.
*
* @param config
* @param storePassword the keystore password
* @param oldKeyPassword the old password for the s1as alias
* @param newKeyPassword the new password for the s1as alias
* @throws RepositoryException
*/
protected void changeS1ASAliasPassword(RepositoryConfig config, String storePassword, String oldKeyPassword, String newKeyPassword) throws RepositoryException {
if (!storePassword.equals(oldKeyPassword) && !oldKeyPassword.equals(newKeyPassword)) {
final PEFileLayout layout = getFileLayout(config);
final File keystore = layout.getKeyStore();
// First see if the alias exists. The user could have deleted it. Any failure in the
// command indicates that the alias does not exist, so we return without error.
String keyStoreType = System.getProperty("javax.net.ssl.keyStoreType");
if (keyStoreType == null) {
keyStoreType = KeyStore.getDefaultType();
}
// add code to change all the aliases that exist rather then change s1as only
List<String> aliases = new ArrayList<>();
FileInputStream is = null;
try {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
is = new FileInputStream(keystore);
keyStore.load(is, storePassword.toCharArray());
Enumeration<String> all = keyStore.aliases();
while (all.hasMoreElements()) {
aliases.add(all.nextElement());
}
} catch (Exception e) {
aliases.add(CERTIFICATE_ALIAS);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ex) {
getLogger().log(Level.SEVERE, UNHANDLED_EXCEPTION, ex);
}
}
}
String[] keytoolCmd = { "-list", "-keystore", keystore.getAbsolutePath(), "-alias", CERTIFICATE_ALIAS };
KeytoolExecutor p = new KeytoolExecutor(keytoolCmd, 30, new String[] { storePassword });
try {
p.execute("s1asKeyPasswordNotChanged", keystore);
} catch (RepositoryException ex) {
return;
}
// change truststore password from the default
for (String alias : aliases) {
keytoolCmd = new String[] { "-keypasswd", "-keystore", keystore.getAbsolutePath(), "-alias", alias };
p = new KeytoolExecutor(keytoolCmd, 30, new String[] { storePassword, oldKeyPassword, newKeyPassword, newKeyPassword });
p.execute("s1asKeyPasswordNotChanged", keystore);
}
}
}
use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.
the class RepositoryManager method getClearPasswordForAlias.
/**
* retrieve clear password from password alias keystore
*
* @param config the {@link RepositoryConfig} which has the alias keystore
* @param password the master password
* @param alias for which the clear text password would returns
* @return the cleartext password
* @throws RepositoryException
*/
public String getClearPasswordForAlias(RepositoryConfig config, String password, String alias) throws RepositoryException {
final PEFileLayout layout = getFileLayout(config);
final File passwordAliases = layout.getPasswordAliasKeystore();
try {
PasswordAdapter p = new PasswordAdapter(passwordAliases.getAbsolutePath(), password.toCharArray());
String clearPwd = p.getPasswordForAlias(alias);
return clearPwd;
} catch (Exception ex) {
return null;
}
}
use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.
the class RepositoryManager method setPermissions.
/**
* Sets the permissions for the domain directory, its config directory, startserv/stopserv scripts etc.
* @param repositoryConfig the {@link RepositoryConfig} to set permissions for
* @throws RepositoryException if unable to set permissions
*/
protected void setPermissions(RepositoryConfig repositoryConfig) throws RepositoryException {
final PEFileLayout layout = getFileLayout(repositoryConfig);
final File domainDir = layout.getRepositoryDir();
try {
chmod("-R 755", domainDir);
} catch (Exception e) {
throw new RepositoryException(STRING_MANAGER.getString("setPermissionError"), e);
}
}
use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.
the class RepositoryManager method changePasswordAliasKeystorePassword.
/**
* Change the password protecting the password alias keystore
*
* @param config the config to find the keystore location from
* @param oldPassword old password
* @param newPassword new password
* @throws RepositoryException
*/
protected void changePasswordAliasKeystorePassword(RepositoryConfig config, String oldPassword, String newPassword) throws RepositoryException {
final PEFileLayout layout = getFileLayout(config);
final File passwordAliases = layout.getPasswordAliasKeystore();
// Change the password of the keystore alias file
if (passwordAliases.exists()) {
try {
PasswordAdapter p = new PasswordAdapter(passwordAliases.getAbsolutePath(), oldPassword.toCharArray());
p.changePassword(newPassword.toCharArray());
} catch (Exception ex) {
throw new RepositoryException(STRING_MANAGER.getString("passwordAliasPasswordNotChanged", passwordAliases), ex);
}
}
}
use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.
the class RepositoryManager method createTimerWal.
/**
* Create the timer database wal file.
* @param config the {@link RepositoryConfig} to get the file locations from
* @throws RepositoryException if an error occured creating the file
*/
protected void createTimerWal(RepositoryConfig config) throws RepositoryException {
final PEFileLayout layout = getFileLayout(config);
final File src = layout.getTimerWalTemplate();
final File dest = layout.getTimerWal();
try {
FileUtils.copy(src, dest);
} catch (IOException ioe) {
throw new RepositoryException(STRING_MANAGER.getString("timerWalNotCreated"), ioe);
}
}
Aggregations