1 23 24 27 28 package com.sun.enterprise.cli.commands; 29 import com.sun.enterprise.cli.framework.*; 30 31 import com.sun.enterprise.util.ProcessExecutor; 32 import com.sun.enterprise.util.ExecException; 33 import com.sun.enterprise.util.OS; 34 import com.sun.enterprise.util.StringUtils; 35 import com.sun.enterprise.util.SystemPropertyConstants; 36 37 import java.util.logging.Logger ; 38 import java.util.logging.Level ; 39 import java.util.Properties ; 40 import java.util.Enumeration ; 41 import java.util.HashMap ; 42 import java.io.IOException ; 43 import com.sun.logging.LogDomains; 44 45 import com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactory; 47 import com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactoryImpl; 48 49 import com.sun.enterprise.admin.servermgmt.RepositoryConfig; 50 import com.sun.enterprise.admin.servermgmt.RepositoryManager; 51 import com.sun.enterprise.admin.servermgmt.DomainsManager; 52 import com.sun.enterprise.admin.servermgmt.DomainConfig; 53 54 55 59 abstract public class BaseLifeCycleCommand extends S1ASCommand 60 { 61 private static final String DEFAULT_FEATURES_PROPERTY_CLASS = 62 "com.sun.enterprise.admin.pluggable.PEClientPluggableFeatureImpl"; 63 67 protected ClientPluggableFeatureFactory _featureFactory = null; 68 69 protected static final String DOMAIN = "domain"; 70 protected static final String DOMAINDIR = "domaindir"; 71 protected static final String MASTER_PASSWORD = "masterpassword"; 72 protected static final String NEW_MASTER_PASSWORD = "newmasterpassword"; 73 protected static final String ADMIN_USER = "adminuser"; 74 protected static final String ADMIN_PASSWORD = "adminpassword"; 75 protected static final String PASSWORD = "password"; 76 protected static final String DEFAULT_MASTER_PASSWORD = RepositoryManager.DEFAULT_MASTER_PASSWORD; 77 protected static final String ADMIN_PORT = "adminport"; 78 protected static final String SAVE_MASTER_PASSWORD = "savemasterpassword"; 79 80 protected final static char ESCAPE_CHAR = '\\'; 81 protected final static char EQUAL_SIGN = '='; 82 protected final static String DELIMITER = ":"; 83 84 85 public BaseLifeCycleCommand() 86 { 87 _featureFactory = createPluggableFeatureFactory(); 88 } 89 90 94 protected Logger getLogger() { 95 return LogDomains.getLogger(LogDomains.CORE_LOGGER); 96 } 97 98 101 protected ClientPluggableFeatureFactory getFeatureFactory() 102 { 103 return _featureFactory; 104 } 105 106 110 private ClientPluggableFeatureFactory createPluggableFeatureFactory() { 111 String featurePropClass = System.getProperty( 112 ClientPluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME, 113 DEFAULT_FEATURES_PROPERTY_CLASS); 114 getLogger().log(Level.FINER, "featurePropClass: " + featurePropClass); 115 ClientPluggableFeatureFactoryImpl featureFactoryImpl = 116 new ClientPluggableFeatureFactoryImpl(getLogger()); 117 ClientPluggableFeatureFactory featureFactory = 118 (ClientPluggableFeatureFactory)featureFactoryImpl.getInstance(featurePropClass); 119 if (featureFactory == null) { 120 getLogger().log(Level.WARNING, 121 "j2eerunner.pluggable_feature_noinit", featurePropClass); 122 } 123 return featureFactory; 124 } 125 126 127 protected DomainConfig getDomainConfig(String domainName) throws CommandException 128 { 129 try { 130 DomainConfig dc = new DomainConfig(domainName, getDomainsRoot()); 131 132 if ( getBooleanOption("verbose") ) { 134 dc.put(DomainConfig.K_VERBOSE, Boolean.TRUE); 135 } 136 if ( getBooleanOption("debug") ) { 137 dc.put(DomainConfig.K_DEBUG, Boolean.TRUE); 138 } 139 140 return dc; 141 142 } catch (Exception e) { 143 throw new CommandException(e); 144 } 145 } 146 147 protected Boolean getSaveMasterPassword(String masterPassword) 148 { 149 Boolean saveMasterPassword = new Boolean (getBooleanOption(SAVE_MASTER_PASSWORD)); 150 if (masterPassword != null && masterPassword.equals(DEFAULT_MASTER_PASSWORD)) { 151 saveMasterPassword = Boolean.TRUE; 152 } 153 return saveMasterPassword; 154 } 155 156 157 protected String getDomainsRoot() throws CommandException 158 { 159 String domainDir = getOption(DOMAINDIR); 160 if (domainDir == null) 161 { 162 domainDir = System.getProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY); 163 } 164 if (domainDir == null) 165 { 166 throw new CommandException(getLocalizedString("InvalidDomainPath", 167 new String [] {domainDir}) ); 168 } 169 return domainDir; 170 } 171 172 protected String getDomainName() throws CommandException 173 { 174 175 String domainName = null; 176 if (operands.isEmpty()) 177 { 178 if (getOption(DOMAIN)!=null) 180 domainName = getOption(DOMAIN); 181 else 182 { 183 final String [] domains = getDomains(); 184 if (domains.length == 0) 185 throw new CommandException(getLocalizedString("NoDomains", 186 new Object [] { 187 getDomainsRoot()})); 188 else if (domains.length > 1) 189 throw new CommandException(getLocalizedString("NoDefaultDomain", 190 new Object [] { 191 getDomainsRoot()})); 192 else 193 domainName = domains[0]; } 195 } 196 else 197 domainName = (String )operands.firstElement(); 198 CLILogger.getInstance().printDebugMessage("domainName = " + domainName); 199 return domainName; 200 } 201 202 203 212 protected String getAdminUser() throws CommandValidationException 213 { 214 String adminUserVal = getOption(ADMIN_USER); 215 if (adminUserVal != null) 216 return adminUserVal; 217 else 218 { 219 adminUserVal = getValuesFromASADMINPREFS(ADMIN_USER); 220 if (adminUserVal != null) 221 { 222 return adminUserVal; 223 } 224 else 227 { 228 adminUserVal = getValuesFromASADMINPREFS(USER); 229 if (adminUserVal != null) return adminUserVal; 230 else if (getBooleanOption(INTERACTIVE)) 232 { 233 try { 235 InputsAndOutputs.getInstance().getUserOutput().print( 236 getLocalizedString("AdminUserPrompt")); 237 return InputsAndOutputs.getInstance().getUserInput().getLine(); 238 } 239 catch (IOException ioe) 240 { 241 throw new CommandValidationException( 242 getLocalizedString("CannotReadOption", 243 new Object []{"ADMIN_USER"})); 244 } 245 } 246 else 247 throw new CommandValidationException(getLocalizedString( 248 "OptionIsRequired", 249 new Object [] {ADMIN_USER})); 250 } 251 } 252 } 253 254 266 protected String getMasterPassword(boolean confirmAndValidate) 267 throws CommandValidationException, CommandException 268 { 269 return getMasterPassword(confirmAndValidate, false); 270 } 271 272 273 286 protected String getMasterPassword(boolean confirmAndValidate, boolean alwaysPrompt) 287 throws CommandValidationException, CommandException 288 { 289 String adminPassword = getPassword(ADMIN_PASSWORD, true, false, false, false, null, null, 292 false, false, false, false); 293 294 if (adminPassword != null && !alwaysPrompt) { 295 String masterPassword = getPassword(MASTER_PASSWORD, false, false, false, false, null, null, 300 false, false, confirmAndValidate, false); 301 if (masterPassword == null) { 302 return DEFAULT_MASTER_PASSWORD; 305 } else { 306 return masterPassword; 307 } 308 } 309 return getPassword(MASTER_PASSWORD, "MasterPasswordPrompt", "MasterPasswordConfirmationPrompt", 314 false, false, false, false, null, null, 315 true, confirmAndValidate, confirmAndValidate, false); 316 } 317 318 319 320 protected String getMasterPassword(RepositoryManager mgr, RepositoryConfig config) 321 throws CommandValidationException, CommandException 322 { 323 return getPassword(MASTER_PASSWORD, "MasterPasswordPrompt", null, 326 false, false, false, true, mgr, config, 327 true, false, false, false); 328 } 329 330 protected String getNewMasterPassword() 331 throws CommandValidationException, CommandException 332 { 333 return getPassword(NEW_MASTER_PASSWORD, 334 "NewMasterPasswordPrompt", "NewMasterPasswordConfirmationPrompt", 335 false, false, false, false, null, null, 336 true, true, true, false); 337 } 338 339 protected HashMap getExtraPasswords(String [] optionNames) 340 throws CommandValidationException, CommandException 341 { 342 HashMap result = new HashMap (); 343 String password; 344 String optionName; 345 for (int i = 0; i < optionNames.length; i++) { 346 optionName = optionNames[i]; 347 NOT_DEPRECATED_PASSWORDFILE_OPTIONS += "|" + optionName; 349 password = getPassword(optionName, "ExtraPasswordPrompt", null, false, false, false, false, null, null, 352 true, false, false, false); 353 result.put(optionName, password); 354 } 355 return result; 356 } 357 358 protected String [] getDomains() throws CommandException 359 { 360 try 361 { 362 DomainsManager mgr = getFeatureFactory().getDomainsManager(); 363 return mgr.listDomains(getDomainConfig(null)); 364 } 365 catch(Exception e) 366 { 367 throw new CommandException(e.getLocalizedMessage()); 368 } 369 } 370 371 protected boolean isWindows() 372 { 373 final String osname = System.getProperty("os.name").toLowerCase(); 374 CLILogger.getInstance().printDebugMessage("osname = " + osname); 375 return osname.indexOf("windows") != -1; 376 } 377 378 protected boolean isSpaceInPath(String path) 379 { 380 return path.indexOf(' ') != -1; 381 } 382 } 383 384 | Popular Tags |