use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class CommandExecutorImpl method executeCommand.
/**
* Runs a command from somewhere OTHER THAN an already-running,
* previously-authorized command.
* <p>
* If a command is already running then it should have a valid Subject and
* that Subject must be used in running a nested command. This
* method uses the internal system admin identity to authorize the command to be run and
* this should never be done if a user has authenticated to the system
* and is running a separate, already-authorized command. This method
* is, therefore, used from some embedded functionality.
*
* @param command
* @param args
* @return
* @throws CommandException
*/
/* package */
ActionReport executeCommand(String command, String... args) throws CommandException {
ParameterMap commandParams = getParameters(command, args);
final ActionReport actionReport = createActionReport();
org.glassfish.api.admin.CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(command, actionReport, embeddedSystemAdministrator.getSubject(), false);
inv.parameters(commandParams).execute();
return actionReport;
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class CommandExecutorImpl method getParameters.
ParameterMap getParameters(String command, String[] args) throws CommandException {
CommandModel commandModel = commandRunner.getModel(command, logger);
if (commandModel == null) {
throw new CommandException("Command lookup failed for command " + command);
}
// Filter out the global options.
// We are interested only in --passwordfile option. No other options are relevant when GlassFish is running in embedded mode.
Parser parser = new Parser(args, 0, ProgramOptions.getValidOptions(), true);
ParameterMap globalOptions = parser.getOptions();
List<String> operands = parser.getOperands();
String[] argv = operands.toArray(new String[operands.size()]);
parser = new Parser(argv, 0, commandModel.getParameters(), false);
ParameterMap options = parser.getOptions();
operands = parser.getOperands();
options.set("DEFAULT", operands);
// if command has a "terse" option, set it in options
if (commandModel.getModelFor("terse") != null)
options.set("terse", Boolean.toString(terse));
// Read the passwords from the password file and set it in command options.
if (globalOptions.size() > 0) {
String pwfile = globalOptions.getOne(ProgramOptions.PASSWORDFILE);
if (pwfile != null && pwfile.length() > 0) {
Map<String, String> passwords = CLIUtil.readPasswordFileOptions(pwfile, false);
for (CommandModel.ParamModel opt : commandModel.getParameters()) {
if (opt.getParam().password()) {
String pwdname = opt.getName();
String pwd = passwords.get(pwdname);
if (pwd != null) {
options.set(pwdname, pwd);
}
}
}
}
}
return options;
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class JsonParameterMapProvider method readFrom.
@Override
public ParameterMap readFrom(Class<ParameterMap> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream in) throws IOException {
JsonObject obj;
try {
JsonParser parser = Json.createParser(in);
if (parser.hasNext()) {
parser.next();
obj = parser.getObject();
} else {
obj = JsonValue.EMPTY_JSON_OBJECT;
}
ParameterMap map = new ParameterMap();
for (String k : obj.keySet()) {
Object value = obj.get(k);
if (value instanceof JsonArray) {
JsonArray array = (JsonArray) value;
for (int i = 0; i < array.size(); i++) {
map.add(k, "" + array.get(i));
}
} else {
map.add(k, "" + value);
}
}
return map;
} catch (Exception ex) {
Logger.getLogger("org.glassfish.admin.rest").log(Level.SEVERE, null, ex);
ParameterMap map = new ParameterMap();
map.add("error", "Entity Parsing Error: " + ex.getMessage());
return map;
}
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class TemplateCommandGetResource method prepareParameters.
private ParameterMap prepareParameters() {
ParameterMap data = new ParameterMap();
processCommandParams(data);
addQueryString(uriInfo.getQueryParameters(), data);
purgeEmptyEntries(data);
adjustParameters(data);
return data;
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class SetDomainConfigResource method setDomainConfig.
@POST
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public Response setDomainConfig(HashMap<String, String> data) {
final Iterator<Entry<String, String>> iterator = data.entrySet().iterator();
if (iterator.hasNext()) {
ParameterMap fixed = new ParameterMap();
Map.Entry entry = iterator.next();
fixed.add("DEFAULT", entry.getKey() + "=" + entry.getValue());
return super.executeCommandLegacyFormat(fixed);
}
// i18n
throw new RuntimeException("You must supply exactly one configuration option.");
}
Aggregations