{
setLoggerLevel();
String domainName = getDomainName();
String agentName = null;
try {
DomainConfig config = getDomainConfig(domainName);
DomainsManager mgr = getFeatureFactory().getDomainsManager();
//domain validation upfront (i.e. before we prompt)
mgr.validateDomain(config, true);
} catch (Exception ex) {
//any exception validating the domain name, and we will
//assume that a node agent has been specified
domainName = null;
}
try {
if (domainName != null) {
/**
com.sun.enterprise.cli.commands.ChangeMasterPasswordCommand cmd =
new com.sun.enterprise.cli.commands.ChangeMasterPasswordCommand();
cmd.changeMasterPassword(domainName);
***/
//WARNING!!! The code below is duplicated in admin-cli ChangeMasterPasswordCommand.java.
//I tried to share the code as illustrated above, but ran into issues.
DomainConfig config = getDomainConfig(domainName);
DomainsManager mgr = getFeatureFactory().getDomainsManager();
//domain validation upfront (i.e. before we prompt)
mgr.validateDomain(config, true);
masterPassword = getMasterPassword(new RepositoryManager(), config);
//getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs,
//readMasterPasswordFile, mgr, config,
//promptUser, confirm, validate)
config.put(DomainConfig.K_MASTER_PASSWORD, masterPassword);
mgr.validateMasterPassword(config);
newMasterPassword = getNewMasterPassword();
validateOptions();
Boolean saveMasterPassword = getSaveMasterPassword(null);
config.put(DomainConfig.K_NEW_MASTER_PASSWORD, newMasterPassword);
config.put(DomainConfig.K_SAVE_MASTER_PASSWORD, saveMasterPassword);
mgr.changeMasterPassword(config);
CLILogger.getInstance().printDetailMessage(_strMgr.getString("DomainPasswordChanged",
new Object[] {domainName}));
//END WARNING!!!
} else {
agentName = getAgentName();
AgentConfig config = new AgentConfig(agentName,
getAgentPath());
AgentManager manager = getAgentManager(config);
//Ensure that the node agent exists
manager.validateNodeAgent(config, true);
masterPassword = getMasterPassword(manager, config);
config.put(AgentConfig.K_MASTER_PASSWORD, masterPassword);
manager.validateMasterPassword(config, true);
//getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs,
//readMasterPasswordFile, mgr, config,
//promptUser, confirm, validate)
newMasterPassword = getNewMasterPassword();
Boolean saveMasterPassword = getSaveMasterPassword(null);
config.put(AgentConfig.K_NEW_MASTER_PASSWORD, newMasterPassword);
config.put(AgentConfig.K_SAVE_MASTER_PASSWORD, saveMasterPassword);
manager.changeMasterPassword(config);
CLILogger.getInstance().printDetailMessage(_strMgr.getString("NodeAgentPasswordChanged",
new Object[] {agentName}));
}
} catch (Exception e) {