use of com.sun.enterprise.admin.util.CommandModelData.ParamModelData in project Payara by payara.
the class CreateDomainCommand method getAdminPassword.
/**
* Get the admin password as a required option.
*/
private char[] getAdminPassword() throws CommandValidationException {
// create a required ParamModel for the password
ParamModelData po = new ParamModelData(ADMIN_PASSWORD, String.class, false, null);
po.prompt = strings.get("AdminPassword");
po.promptAgain = strings.get("AdminPasswordAgain");
po.param._password = true;
return getPassword(po, SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD, true);
}
use of com.sun.enterprise.admin.util.CommandModelData.ParamModelData in project Payara by payara.
the class CreateDomainCommand method getMasterPassword.
/**
* Get the master password as a required option (by default it is not required)
*/
private char[] getMasterPassword() throws CommandValidationException {
// create a required ParamModel for the password
ParamModelData po = new ParamModelData(MASTER_PASSWORD, String.class, false, /* optional */
null);
po.prompt = strings.get("MasterPassword");
po.promptAgain = strings.get("MasterPasswordAgain");
po.param._password = true;
return getPassword(po, DEFAULT_MASTER_PASSWORD, true);
}
use of com.sun.enterprise.admin.util.CommandModelData.ParamModelData in project Payara by payara.
the class StartDomainCommand method doAdminPasswordCheck.
/*
* Check to make sure that at least one admin user is able to login.
* If none is found, then prompt for an admin password.
*
* NOTE: this depends on launcher.setup having already been called.
*/
private void doAdminPasswordCheck() throws CommandException {
String arfile = launcher.getAdminRealmKeyFile();
if (arfile != null) {
try {
FileRealmHelper ar = new FileRealmHelper(arfile);
if (!ar.hasAuthenticatableUser()) {
// Prompt for the password for the first user and set it
Set<String> names = ar.getUserNames();
if (names == null || names.isEmpty()) {
throw new CommandException("no admin users");
}
String auser = names.iterator().next();
ParamModelData npwo = new ParamModelData(newpwName, String.class, false, null);
npwo.prompt = strings.get("new.adminpw", auser);
npwo.promptAgain = strings.get("new.adminpw.again", auser);
npwo.param._password = true;
logger.info(strings.get("new.adminpw.prompt"));
char[] npwArr = super.getPassword(npwo, null, true);
String npw = npwArr != null ? new String(npwArr) : null;
if (npw == null) {
throw new CommandException(strings.get("no.console"));
}
ar.updateUser(auser, auser, npw.toCharArray(), null);
ar.persist();
}
} catch (IOException ioe) {
throw new CommandException(ioe);
}
}
}
use of com.sun.enterprise.admin.util.CommandModelData.ParamModelData in project Payara by payara.
the class CreateLocalInstanceCommand method saveMasterPassword.
/**
* If --savemasterpassword=true,
* then --usemasterpassword is set to true also
* If AS_ADMIN_MASTERPASSWORD from --passwordfile exists that is used.
* If it does not exist, the user is asked to enter the master password.
* The password is validated against the keystore if it exists. If successful, master-password
* is saved to the server instance directory <glassfish-install>/nodes/<host name>/master-password.
* If the password entered does not match the keystore, master-password is not
* saved and a warning is displayed. The command is still successful.
* The default value of --usemasterpassword is false.
*
* When savemasterpassword is false, the keystore is encrypted with a well-known password
* that is built into the system, thus affording no additional security.
* The master password must be the same for all instances in a domain.
*
* @throws CommandException
*/
private void saveMasterPassword() throws CommandException {
masterPasswordOption = new ParamModelData(CLIConstants.MASTER_PASSWORD, String.class, false, null);
masterPasswordOption.prompt = Strings.get("MasterPassword");
masterPasswordOption.promptAgain = Strings.get("MasterPasswordAgain");
masterPasswordOption.param._password = true;
if (saveMasterPassword)
useMasterPassword = true;
if (useMasterPassword)
masterPassword = getPassword(masterPasswordOption, DEFAULT_MASTER_PASSWORD, true) != null ? new String(getPassword(masterPasswordOption, DEFAULT_MASTER_PASSWORD, true)) : null;
if (masterPassword == null)
masterPassword = DEFAULT_MASTER_PASSWORD;
if (saveMasterPassword) {
File mp = new File(new File(getServerDirs().getServerDir(), "config"), "keystore.jks");
if (mp.canRead()) {
if (verifyMasterPassword(masterPassword)) {
createMasterPasswordFile(masterPassword);
} else {
logger.info(Strings.get("masterPasswordIncorrect"));
}
} else {
createMasterPasswordFile(masterPassword);
}
}
}
use of com.sun.enterprise.admin.util.CommandModelData.ParamModelData in project Payara by payara.
the class RemoteAdminCommand method parseMetadata.
/**
* Parse the XML metadata for the command on the input stream.
*
* @param in the input stream
* @return the set of ValidOptions
*/
private CommandModel parseMetadata(InputStream in, StringBuilder errors) {
if (logger.isLoggable(Level.FINER)) {
// XXX - assume "debug" == "FINER"
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
FileUtils.copy(in, baos, 0);
} catch (IOException ex) {
}
in = new ByteArrayInputStream(baos.toByteArray());
String response = baos.toString();
logger.finer("------- RAW METADATA RESPONSE ---------");
logger.finer(response);
logger.finer("------- RAW METADATA RESPONSE ---------");
}
CachedCommandModel cm = new CachedCommandModel(name);
boolean sawFile = false;
try {
DocumentBuilder d = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = d.parse(in);
NodeList cmd = doc.getElementsByTagName("command");
Node cmdnode = cmd.item(0);
if (cmdnode == null) {
Node report = doc.getElementsByTagName("action-report").item(0);
String cause = getAttr(report.getAttributes(), "failure-cause");
if (ok(cause))
errors.append(cause);
else {
// message-part
Node mp = report.getFirstChild();
if (mp != null)
cause = getAttr(mp.getAttributes(), "message");
if (ok(cause))
errors.append(cause);
}
// wrong with command implementation
return null;
}
NamedNodeMap cmdattrs = cmdnode.getAttributes();
usage = getAttr(cmdattrs, "usage");
cm.setUsage(usage);
String dashOk = getAttr(cmdattrs, "unknown-options-are-operands");
if (dashOk != null)
cm.dashOk = Boolean.parseBoolean(dashOk);
NodeList opts = doc.getElementsByTagName("option");
for (int i = 0; i < opts.getLength(); i++) {
Node n = opts.item(i);
NamedNodeMap attributes = n.getAttributes();
String sn = getAttr(attributes, "short");
String def = getAttr(attributes, "default");
String obs = getAttr(attributes, "obsolete");
String alias = getAttr(attributes, "alias");
ParamModelData opt = new ParamModelData(getAttr(attributes, "name"), typeOf(getAttr(attributes, "type")), Boolean.parseBoolean(getAttr(attributes, "optional")), def, ok(sn) ? sn : null, ok(obs) ? Boolean.parseBoolean(obs) : false, alias);
if (getAttr(attributes, "type").equals("PASSWORD")) {
opt.param._password = true;
opt.prompt = getAttr(attributes, "prompt");
opt.promptAgain = getAttr(attributes, "promptAgain");
}
cm.add(opt);
if (opt.getType() == File.class)
sawFile = true;
}
// should be only one operand item
opts = doc.getElementsByTagName("operand");
for (int i = 0; i < opts.getLength(); i++) {
Node n = opts.item(i);
NamedNodeMap attributes = n.getAttributes();
Class<?> type = typeOf(getAttr(attributes, "type"));
if (type == File.class) {
sawFile = true;
}
int min = Integer.parseInt(getAttr(attributes, "min"));
String max = getAttr(attributes, "max");
boolean multiple = false;
if (max.equals("unlimited")) {
multiple = true;
// XXX - should convert to array of whatever
if (type == File.class) {
type = File[].class;
} else {
type = List.class;
}
}
ParamModelData pm = new ParamModelData(getAttr(attributes, "name"), type, min == 0, null);
pm.param._primary = true;
pm.param._multiple = multiple;
cm.add(pm);
}
/*
* If one of the options or operands is a FILE,
* make sure there's also a --upload option available.
* XXX - should only add it if it's not present
* XXX - should just define upload parameter on remote command
*/
if (sawFile) {
cm.add(new ParamModelData("upload", Boolean.class, true, null));
addedUploadOption = true;
cm.setAddedUploadOption(true);
}
} catch (ParserConfigurationException pex) {
// ignore for now
return null;
} catch (SAXException sex) {
// ignore for now
return null;
} catch (IOException ioex) {
// ignore for now
return null;
}
return cm;
}
Aggregations