FileDocCategorySizeDatePackage
MasterPasswordFileManager.javaAPI DocGlassfish v2 API6576Fri May 04 22:24:30 BST 2007com.sun.enterprise.admin.servermgmt

MasterPasswordFileManager

public class MasterPasswordFileManager extends KeystoreManager
The RepositoryManager serves as a common base class for the following PEDomainsManager, PEInstancesManager, AgentManager (the SE Node Agent). Its purpose is to abstract out any shared functionality related to lifecycle management of domains, instances and node agents. This includes creation, deletion, listing, and starting and stopping.
author
kebbs

Fields Summary
private static final String
MASTER_PASSWORD_ALIAS
private static final String
ENCODED_CHARSET
private static final int
SALT_SIZE
private static final com.sun.enterprise.util.i18n.StringManager
_strMgr
Constructors Summary
public MasterPasswordFileManager()
Creates a new instance of RepositoryManager

                  

           
      
        super();
    
Methods Summary
protected voidchangeMasterPasswordInMasterPasswordFile(RepositoryConfig config, java.lang.String newPassword, boolean saveMasterPassword)
Changes the master password in the master password file

param
saveMasterPassword
param
config
param
newPassword
throws
RepositoryException

        deleteMasterPasswordFile(config);
        if (saveMasterPassword) {
            createMasterPasswordFile(config, newPassword);
        }         
    
protected voidcreateMasterPasswordFile(RepositoryConfig config, java.lang.String masterPassword)
Create the master password keystore. This routine can also modify the master password if the keystore already exists

param
config
param
masterPassword
throws
RepositoryException

        final PEFileLayout layout = getFileLayout(config);
        final File pwdFile = layout.getMasterPasswordFile();                     
        try {                    
            PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), 
                getMasterPasswordPassword(config));
            p.setPasswordForAlias(MASTER_PASSWORD_ALIAS, masterPassword.getBytes());
            chmod("600", pwdFile);
        } catch (Exception ex) {                        
            throw new RepositoryException(_strMgr.getString("masterPasswordFileNotCreated", pwdFile),
                ex);
        } 
    
protected voiddeleteMasterPasswordFile(RepositoryConfig config)

        final PEFileLayout layout = getFileLayout(config);
        final File pwdFile = layout.getMasterPasswordFile();    
        pwdFile.delete();
    
private char[]getMasterPasswordPassword(RepositoryConfig config)

return
The password protecting the master password keywtore

        //XXX fixed String
        return MASTER_PASSWORD_ALIAS.toCharArray();
    
public java.lang.StringreadMasterPasswordFile(RepositoryConfig config)
Return the master password stored in the master password keystore.

param
config
throws
RepositoryException
return

               
        final PEFileLayout layout = getFileLayout(config);
        final File pwdFile = layout.getMasterPasswordFile();        
        if (pwdFile.exists()) {            
            try {                    
                PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), 
                    getMasterPasswordPassword(config));
                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;
        }