1 23 24 27 28 package com.sun.enterprise.cli.commands; 29 30 import com.sun.enterprise.cli.framework.CommandValidationException; 31 import com.sun.enterprise.cli.framework.CommandException; 32 import com.sun.enterprise.cli.framework.CLILogger; 33 34 35 import com.sun.enterprise.admin.servermgmt.DomainConfig; 36 import com.sun.enterprise.admin.servermgmt.RepositoryManager; 37 import com.sun.enterprise.admin.servermgmt.DomainsManager; 38 import com.sun.enterprise.admin.servermgmt.DomainException; 39 40 41 45 public class ChangeMasterPasswordCommand extends BaseLifeCycleCommand 46 { 47 private String newMasterPassword = null; 48 private String masterPassword = null; 49 50 51 public ChangeMasterPasswordCommand() 52 { 53 } 54 55 60 public boolean validateOptions() throws CommandValidationException 61 { 62 super.validateOptions(); 63 64 if (!isPasswordValid(newMasterPassword)) { 66 throw new CommandValidationException(getLocalizedString("PasswordLimit", 67 new Object []{NEW_MASTER_PASSWORD})); 68 } 69 70 return true; 71 } 72 73 public void changeMasterPassword(String domainName) 74 throws DomainException, CommandValidationException, CommandException 75 { 76 DomainConfig config = getDomainConfig(domainName); 79 DomainsManager mgr = getFeatureFactory().getDomainsManager(); 80 mgr.validateDomain(config, true); 82 83 masterPassword = getMasterPassword(new RepositoryManager(), config); 84 config.put(DomainConfig.K_MASTER_PASSWORD, masterPassword); 88 mgr.validateMasterPassword(config); 89 90 newMasterPassword = getNewMasterPassword(); 91 validateOptions(); 92 Boolean saveMasterPassword = getSaveMasterPassword(null); 93 config.put(DomainConfig.K_NEW_MASTER_PASSWORD, newMasterPassword); 94 config.put(DomainConfig.K_SAVE_MASTER_PASSWORD, saveMasterPassword); 95 mgr.changeMasterPassword(config); 96 } 98 99 103 public void runCommand() 104 throws CommandException, CommandValidationException 105 { 106 String domainName = null; 107 try { 108 setLoggerLevel(); 109 domainName = getDomainName(); 110 changeMasterPassword(domainName); 111 CLILogger.getInstance().printDetailMessage(getLocalizedString("DomainPasswordChanged", 112 new Object [] {domainName})); 113 } catch (Exception e) { 114 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 115 throw new CommandException(getLocalizedString("ExceptionChangingPassword", 116 new Object [] {domainName}), e); 117 } 118 } 119 } | Popular Tags |