FileDocCategorySizeDatePackage
ChangeAdminPasswordCommand.javaAPI DocGlassfish v2 API6359Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

ChangeAdminPasswordCommand

public class ChangeAdminPasswordCommand extends S1ASCommand
This class gets called when change-admin-password command is invoked. CLI will prompt the user for the password.

Fields Summary
private static final String
ADMIN_PASSWORD
private static final String
PASSWORD
private static final String
INTERACTIVE
private static final String
OLD_ADMIN_PASSWORD
private static final String
NEW_ADMIN_PASSWORD
private String
newPassword
private String
oldPassword
Constructors Summary
Methods Summary
private java.lang.StringgetNewAdminPassword()

        return getPassword(NEW_ADMIN_PASSWORD, 
            "NewAdminPasswordPrompt", "NewAdminPasswordConfirmationPrompt", 
            false, false, false, false, null, null, 
            true, true, true, false);
    
private java.lang.StringgetOldAdminPassword()

    
    
       
          
    
        return getPassword(OLD_ADMIN_PASSWORD, 
            "OldAdminPasswordPrompt", null, 
            false, false, false, false, null, null, 
            true, false, true, false);
    
public voidrunCommand()
executes the command

        if (!validateOptions())
            throw new CommandValidationException("Validation is false");

        final String host = getHost();
        final int port = getPort();
        final String userName = getUser();
        
            //use http connector
        MBeanServerConnection mbsc = getMBeanServerConnection(host, port, userName, oldPassword);
        final String objectName = getObjectName();
        final Object[] params = getParamsInfo();
        final String operationName = getOperationName();
        final String[] types = getTypesInfo();

        try
        { 
	    //if (System.getProperty("Debug") != null) printDebug(mbsc, objectName);
            Object returnValue = mbsc.invoke(new ObjectName(objectName), 
					     operationName, params, types);
            handleReturnValue(returnValue);
            updateLoginFile(userName, host, port);
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                           "CommandSuccessful",
                                                           new Object[] {name}));
        }
        catch(Exception e)
        {
            displayExceptionMessage(e);
        }        
    
private voidupdateLoginFile(java.lang.String user, java.lang.String host, int port)

        try {
            final LoginInfoStore store = LoginInfoStoreFactory.getStore(null);
            if (store.exists(host, port))
            {
                store.store(new LoginInfo(host, port, user, newPassword), true);
                CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                               "SuccessfullyUpdatedLoginInfo"));
            }
        }
        catch(final Exception e) {
                //ignore message if unable to update .asadminpass
        }
    
public booleanvalidateOptions()
This method prompts the user for the old and new adminpassword.

    	super.validateOptions();
        
        try {
            /**
             * set interactive to true so that passwords can be prompted.
             **/
            setOption(INTERACTIVE, "true");
            //if user is not entered on command line, prompt for the user name.
            final String sUser = getUser();
            setOption(USER, sUser);
                
            oldPassword = getOldAdminPassword();
            setOption(PASSWORD, oldPassword);
            newPassword = getNewAdminPassword();
            setOption(ADMIN_PASSWORD, newPassword);
        }
        catch (CommandException ce) {
            throw new CommandValidationException(ce.getLocalizedMessage());
        }                
        
        return true;