use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class RealmAssignService 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
Map<String, Set<String>> attributeValues = null;
if ((datafile != null) || (attrValues != null)) {
attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
attributeValues = processFileAttributes(attributeValues);
}
IOutput outputWriter = getOutputWriter();
String[] params = { realm, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set assignableServices = ocm.getAssignableServices();
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = amir.getRealmIdentity();
Set dynAssignableServices = ai.getAssignableServices();
if (assignableServices.contains(serviceName)) {
ocm.assignService(serviceName, attributeValues);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
}
if (dynAssignableServices.contains(serviceName)) {
ai.assignService(serviceName, attributeValues);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
} catch (SSOException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmAssignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput 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.IOutput in project OpenAM by OpenRock.
the class GetAttributeDefaults 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 schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
ServiceSchema ss = getServiceSchema();
IOutput outputWriter = getOutputWriter();
String[] params = { serviceName, schemaType, subSchemaName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SCHEMA_ATTR_DEFAULTS", params);
Map attrValues = ss.getAttributeDefaults();
retainValues(rc, attrValues);
maskPasswordValues(ss, attrValues);
if (!attrValues.isEmpty()) {
outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("schema-get-attribute-defaults-result"), attrValues));
outputWriter.printlnMessage(getResourceString("schema-get-attribute-defaults-succeed"));
} else {
outputWriter.printlnMessage(getResourceString("schema-get-attribute-defaults-no-matching-attr"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SCHEMA_ATTR_DEFAULTS", params);
}
use of com.sun.identity.cli.IOutput 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.IOutput in project OpenAM by OpenRock.
the class StopRecord method handleRequest.
/**
* Stop recording
* @param rc Request Context.
* @throws CLIException
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
IOutput outputWriter = getOutputWriter();
String serverName = getStringOptionValue(IArgument.SERVER_NAME);
debug.message("Stop recording: serverURL : '{}'", serverName);
String[] argsAttempt = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_STOP_RECORD", argsAttempt);
SSOToken adminSSOToken = getAdminSSOToken();
try {
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
String message = "ServerName '" + serverName + "' doesn't exist";
debug.error(message);
outputWriter.printlnMessage(message);
String[] args = { serverName, message };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
return;
}
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
RestCommand restCommand = new RestCommand();
String result = restCommand.sendRestCommand(adminSSOToken.getTokenID(), new URL(serverName + "/json/" + RecordConstants.RECORD_REST_ENDPOINT + "?_action=" + RecordConstants.STOP_ACTION), "POST", headers, "");
debug.message("Stop recording with success. Result : '{}'", result);
if (result.isEmpty()) {
outputWriter.printlnMessage("Result from server is empty. An error occurred. See debug logs for more " + "information");
String[] args = { serverName, "Result from server is empty. An error occurred." };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
}
String[] args = { serverName, result };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_STOP_RECORD", args);
outputWriter.printlnMessage(result);
} catch (IOException | SMSException | SSOException e) {
debug.error("An error occurred", e);
outputWriter.printlnMessage(e.getMessage());
String[] args = { serverName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
}
}
Aggregations