Search in sources :

Example 6 with PasswordAdapter

use of com.sun.enterprise.security.store.PasswordAdapter in project Payara by payara.

the class DomainSecurity method createPasswordAliasKeystore.

/**
 * Create the password alias keystore (initially empty)
 *
 * @param pwFile File to store encrypted password.
 * @param password password protecting the keystore
 * @throws RepositoryException if any error occurs in creation.
 */
void createPasswordAliasKeystore(File pwFile, String password) throws RepositoryException {
    try {
        PasswordAdapter p = new PasswordAdapter(pwFile.getAbsolutePath(), password.toCharArray());
        p.writeStore();
    } catch (Exception ex) {
        throw new RepositoryException(_strMgr.getString("passwordAliasKeystoreNotCreated", pwFile), ex);
    }
}
Also used : RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException) PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) IOException(java.io.IOException) RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException)

Example 7 with PasswordAdapter

use of com.sun.enterprise.security.store.PasswordAdapter in project Payara by payara.

the class ChangeNodeMasterPasswordCommand method createMasterPasswordFile.

/**
 * Create the master password keystore. This routine can also modify the master password
 * if the keystore already exists
 *
 * @throws CommandException
 */
protected void createMasterPasswordFile() throws CommandException {
    final File pwdFile = new File(this.getServerDirs().getAgentDir(), MASTER_PASSWORD_ALIAS);
    try {
        PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), MASTER_PASSWORD_ALIAS.toCharArray());
        p.setPasswordForAlias(MASTER_PASSWORD_ALIAS, newPassword.getBytes());
        FileProtectionUtility.chmod0600(pwdFile);
    } catch (Exception ex) {
        throw new CommandException(strings.get("masterPasswordFileNotCreated", pwdFile), ex);
    }
}
Also used : PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException)

Example 8 with PasswordAdapter

use of com.sun.enterprise.security.store.PasswordAdapter in project Payara by payara.

the class CreateLocalInstanceCommand method createMasterPasswordFile.

/**
 * Create the master password keystore. This routine can also modify the master password
 * if the keystore already exists
 * @param masterPassword
 * @throws CommandException
 */
protected void createMasterPasswordFile(String masterPassword) throws CommandException {
    final File pwdFile = new File(this.getServerDirs().getAgentDir(), MASTER_PASSWORD_ALIAS);
    try {
        PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), MASTER_PASSWORD_ALIAS.toCharArray());
        p.setPasswordForAlias(MASTER_PASSWORD_ALIAS, masterPassword.getBytes());
        FileProtectionUtility.chmod0600(pwdFile);
    } catch (Exception ex) {
        throw new CommandException(Strings.get("masterPasswordFileNotCreated", pwdFile), ex);
    }
}
Also used : PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) UnknownHostException(java.net.UnknownHostException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) CommandException(org.glassfish.api.admin.CommandException)

Example 9 with PasswordAdapter

use of com.sun.enterprise.security.store.PasswordAdapter in project Payara by payara.

the class MasterPasswordFileManager method changeMasterPasswordInMasterPasswordFile.

/**
 * Changes the master password in the master password file
 * @param saveMasterPassword
 * @param config
 * @param newPassword
 * @throws RepositoryException
 */
public void changeMasterPasswordInMasterPasswordFile(File pwdFile, String newPassword, boolean saveMasterPassword) throws RepositoryException {
    FileUtils.deleteFile(pwdFile);
    if (saveMasterPassword) {
        try {
            PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), getMasterPasswordPassword());
            p.setPasswordForAlias(MASTER_PASSWORD_ALIAS, newPassword.getBytes());
            FileProtectionUtility.chmod0600(pwdFile);
        } catch (Exception ex) {
            throw new RepositoryException(_strMgr.getString("masterPasswordFileNotCreated", pwdFile), ex);
        }
    }
}
Also used : PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter)

Example 10 with PasswordAdapter

use of com.sun.enterprise.security.store.PasswordAdapter in project Payara by payara.

the class MasterPasswordFileManager method readMasterPasswordFile.

/**
 * Return the master password stored in the master password keystore.
 * @param config
 * @throws RepositoryException
 * @return
 */
public String readMasterPasswordFile(RepositoryConfig config) throws RepositoryException {
    final PEFileLayout layout = getFileLayout(config);
    final File pwdFile = layout.getMasterPasswordFile();
    if (pwdFile.exists()) {
        try {
            PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), getMasterPasswordPassword());
            return p.getPasswordForAlias(MASTER_PASSWORD_ALIAS);
        } catch (Exception ex) {
            throw new RepositoryException(_strMgr.getString("masterPasswordFileNotRead", pwdFile), ex);
        }
    } else {
        // Return null if the password file does not exist.
        return null;
    }
}
Also used : PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) File(java.io.File)

Aggregations

PasswordAdapter (com.sun.enterprise.security.store.PasswordAdapter)11 PEFileLayout (com.sun.enterprise.admin.servermgmt.pe.PEFileLayout)5 File (java.io.File)4 ZipFile (com.sun.enterprise.util.zip.ZipFile)3 IOException (java.io.IOException)2 CommandException (org.glassfish.api.admin.CommandException)2 RepositoryException (com.sun.enterprise.admin.servermgmt.RepositoryException)1 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)1 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)1 UnknownHostException (java.net.UnknownHostException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 CommandValidationException (org.glassfish.api.admin.CommandValidationException)1 SSHLauncher (org.glassfish.cluster.ssh.launcher.SSHLauncher)1