use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class CreateXACML method getXacmlInputStream.
private InputStream getXacmlInputStream(String realm) throws CLIException {
InputStream inputStream;
String datafile = getStringOptionValue(IArgument.XML_FILE);
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
inputStream = new ByteArrayInputStream(datafile.getBytes());
} else {
try {
inputStream = new FileInputStream(datafile);
} catch (FileNotFoundException e) {
debugError("CreateXACML.handleRequest", e);
logException(realm, e);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
return inputStream;
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class AddAMSDKIdRepoPlugin method loadLDIFs.
private void loadLDIFs() throws Exception {
CommandManager mgr = getCommandManager();
List ldifs = getLDIFs();
for (Iterator i = directoryServers.iterator(); i.hasNext(); ) {
String dshost = (String) i.next();
try (ConnectionFactory factory = getLDAPConnection(new DSEntry(dshost));
Connection ld = factory.getConnection()) {
String dbName = LDAPUtils.getDBName(basedn, ld);
for (Iterator j = ldifs.iterator(); j.hasNext(); ) {
String file = (String) j.next();
String content = CLIUtil.getFileContent(mgr, file);
String swapped = tagswap(content, dbName);
loadLDIF(ld, swapped);
}
}
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class LoadSchema method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
boolean continueFlag = isOptionSet(IArgument.CONTINUE);
IOutput outputWriter = getOutputWriter();
List xmlFiles = (List) rc.getOption(IArgument.XML_FILE);
ServiceManager ssm = null;
try {
ssm = new ServiceManager(adminSSOToken);
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
CommandManager mgr = getCommandManager();
boolean bError = false;
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
String[] param = { CLIConstants.WEB_INPUT };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
loadSchemaXML(ssm, (String) xmlFiles.iterator().next());
outputWriter.printlnMessage(getResourceString("schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
} else {
for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
String file = (String) i.next();
String[] param = { file };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
loadSchema(ssm, file);
outputWriter.printlnMessage(getResourceString("schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
} catch (CLIException e) {
bError = true;
if (continueFlag) {
outputWriter.printlnError(getResourceString("schema-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
}
}
}
// if continue flag is on; throw cannot process exception
if (bError) {
throw new CLIException(getResourceString("one-or-more-services-not-added"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class UpdateService method handleRequest.
/**
* Updates service schema. Delete the service schema if it exists and
* load the schema.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
boolean continueFlag = isOptionSet(IArgument.CONTINUE);
IOutput outputWriter = getOutputWriter();
List xmlFiles = (List) rc.getOption(IArgument.XML_FILE);
ServiceManager ssm = null;
try {
ssm = new ServiceManager(adminSSOToken);
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
String strXML = (String) xmlFiles.iterator().next();
try {
List serviceNames = getServiceNames(SMSSchema.getXMLDocument(strXML, true));
deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
loadSchemaXML(ssm, strXML);
outputWriter.printlnMessage(getResourceString("service-updated"));
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} else {
for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
String file = (String) i.next();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
List serviceNames = getServiceNames(SMSSchema.getXMLDocument(fis));
deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
loadSchema(ssm, file);
outputWriter.printlnMessage(getResourceString("service-updated"));
} catch (CLIException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
} catch (SMSException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (FileNotFoundException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ie) {
//igore if file input stream cannot be closed.
}
}
}
}
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class UpdateAuthConfigurationEntries method parse.
private List parse(String fileName, List listEntries) throws CLIException, AMConfigurationException {
CommandManager mgr = getCommandManager();
List results = null;
if (fileName != null) {
results = parse(mgr, fileName);
}
if ((listEntries != null) && !listEntries.isEmpty()) {
if (results != null) {
results.addAll(parse(mgr, listEntries));
} else {
results = parse(mgr, listEntries);
}
}
return (results == null) ? new ArrayList() : results;
}
Aggregations