use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RealmGetAssignableServices 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();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String[] params = { realm };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set serviceNames = ocm.getAssignableServices();
Set dynamicServiceNames = getAssignableDynamicServiceNames(adminSSOToken, realm);
if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
if ((serviceNames != null) && !serviceNames.isEmpty()) {
serviceNames.addAll(dynamicServiceNames);
} else {
serviceNames = dynamicServiceNames;
}
}
IOutput outputWriter = getOutputWriter();
if ((serviceNames != null) && !serviceNames.isEmpty()) {
String msg = getResourceString("realm-getassignable-services-result");
outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
outputWriter.printlnMessage(getResourceString("realm-getassignable-services-succeed"));
} else {
outputWriter.printlnMessage(getResourceString("realm-getassignable-services-no-services"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignableServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignableServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignableServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ExportServiceConfiguration method handleRequest.
/**
* Handles request.
*
* @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();
String outputFile = getStringOptionValue(IArgument.OUTPUT_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
FileOutputStream fout = null;
String[] param = { "tty" };
String[] paramException = { "tty", "" };
try {
if ((outputFile != null) && (outputFile.length() > 0)) {
fout = new FileOutputStream(outputFile);
param[0] = outputFile;
paramException[0] = outputFile;
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_EXPORT_SM_CONFIG_DATA", param);
ServiceManager sm = new ServiceManager(adminSSOToken);
AMEncryption encryptObj = new JCEEncryption();
((ConfigurableKey) encryptObj).setPassword(encryptSecret);
String resultXML = sm.toXML(encryptObj);
resultXML += "<!-- " + Hash.hash(encryptSecret) + " -->";
if (fout != null) {
fout.write(resultXML.getBytes("UTF-8"));
} else {
System.out.write(resultXML.getBytes("UTF-8"));
}
getOutputWriter().printlnMessage(getResourceString("export-service-configuration-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_SM_CONFIG_DATA", param);
} catch (UnsupportedEncodingException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (Exception e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException ioe) {
//ignored
}
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AddAttributeSchema method addAttributeSchemaXML.
private void addAttributeSchemaXML(ServiceSchema ss, String serviceName, String schemaType, String xml) throws CLIException {
ByteArrayInputStream bis = null;
try {
bis = new ByteArrayInputStream(xml.getBytes());
ss.addAttributeSchema(bis);
} catch (SSOException e) {
String[] args = { CLIConstants.WEB_INPUT, schemaType, xml, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_ADD_ATTRIBUTE_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { CLIConstants.WEB_INPUT, schemaType, xml, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_ADD_ATTRIBUTE_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ie) {
//ignore if file input stream cannot be closed.
}
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AddPluginInterface 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();
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String i18nKey = getStringOptionValue(ARGUMENT_I18N_KEY);
String interfaceName = getStringOptionValue(ARGUMENT_INTERFACE_NAME);
String pluginName = getStringOptionValue(ARGUMENT_PLUGIN_NAME);
ServiceSchemaManager ssm = getServiceSchemaManager();
IOutput outputWriter = getOutputWriter();
try {
String[] params = { serviceName, pluginName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_PLUGIN_INTERFACE", params);
ssm.addPluginInterface(pluginName, interfaceName, i18nKey);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_PLUGIN_INTERFACE", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-interface-succeed"), (Object[]) params));
} catch (SSOException e) {
String[] args = { serviceName, pluginName, e.getMessage() };
debugError("AddPluginInterface.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serviceName, pluginName, e.getMessage() };
debugError("AddPluginInterface.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AddSubConfiguration 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();
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String subConfigName = getStringOptionValue(IArgument.SUB_CONFIGURATION_NAME);
String realmName = getStringOptionValue(IArgument.REALM_NAME);
String subConfigId = getStringOptionValue(IArgument.SUB_CONFIGURATION_ID);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
int priority = 0;
String strPriority = getStringOptionValue(OPTION_PRIORITY);
if ((strPriority != null) && (strPriority.length() > 0)) {
try {
priority = Integer.parseInt(strPriority);
} catch (NumberFormatException ex) {
throw new CLIException(getResourceString("add-sub-configuration-priority-no-integer"), ExitCodes.INVALID_OPTION_VALUE);
}
}
Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
attributeValues = processFileAttributes(attributeValues);
if ((realmName == null) || (realmName.length() == 0)) {
addSubConfigToRoot(serviceName, subConfigName, subConfigId, attributeValues, priority);
} else {
addSubConfigToRealm(realmName, serviceName, subConfigName, subConfigId, attributeValues, priority);
}
}
Aggregations