1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import javax.management.MBeanServerConnection ; 29 import javax.management.ObjectName ; 30 31 import java.io.IOException ; 32 33 40 public class FileUserCommand extends S1ASCommand 41 { 42 private static final String USER_PASSWORD = "userpassword"; 43 private static final String FILE_USER_NAME = "fileuser"; 44 45 protected String getPasswordOptionName() { 46 return USER_PASSWORD; 47 } 48 49 50 protected String getPasswordPrompt() 51 { 52 return "FileUserPasswordPrompt"; 53 } 54 55 56 protected String getPasswordConfirmationPrompt() 57 { 58 return "FileUserPasswordConfirmationPrompt"; 59 } 60 61 62 protected boolean confirmPassword() { 63 return true; 64 } 65 66 83 84 protected String getUserOptionName() { 85 return FILE_USER_NAME; 86 } 87 88 89 protected String getUserPrompt() 90 { 91 return "FileUserPrompt"; 92 } 93 94 95 101 protected String getPasswordOption() 102 throws CommandValidationException, CommandException 103 { 104 return getPassword(getPasswordOptionName(), getPasswordPrompt(), 107 getPasswordConfirmationPrompt(), 108 true, false, false, false, null, null, 109 true, confirmPassword(), false, true); 110 } 111 112 113 private String getUserName() throws CommandValidationException 114 { 115 String userName; 116 if ((getOperands() != null) && (getOperands().size() != 0)) 117 userName = (String ) getOperands().get(0); 118 else { 120 try { 121 InputsAndOutputs.getInstance().getUserOutput().print( 122 getLocalizedString(this.getUserPrompt())); 123 userName = InputsAndOutputs.getInstance().getUserInput().getLine(); 124 } 125 catch (IOException ioe) 126 { 127 throw new CommandValidationException( 128 getLocalizedString("CannotReadOption", 129 new Object []{getUserOptionName()})); 130 } 131 } 132 133 return userName; 134 } 135 136 137 140 public boolean validateOptions() throws CommandValidationException 141 { 142 return super.validateOptions(); 143 } 144 145 public void runCommand() throws CommandException, CommandValidationException 146 { 147 validateOptions(); 148 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 150 getUser(), getPassword()); 151 final String objectName = getObjectName(); 152 final Object [] params = getParamsInfo(); 153 final String operationName = getOperationName(); 154 final String [] types = getTypesInfo(); 155 156 params[0] = getUserName(); 158 params[1] = getPasswordOption(); 160 try 161 { 162 Object returnValue = mbsc.invoke(new ObjectName (objectName), 164 operationName, params, types); 165 handleReturnValue(returnValue); 166 CLILogger.getInstance().printDetailMessage(getLocalizedString( 167 "CommandSuccessful", 168 new Object [] {name})); 169 } 170 catch(Exception e) 171 { 172 displayExceptionMessage(e); 173 } 174 } 175 } 176 | Popular Tags |