use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class ShowAgentGroup 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
String outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
String[] params = { realm, agentGroupName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentGroupName, "agent group did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
Object[] p = { agentGroupName };
String msg = MessageFormat.format(getResourceString("show-agent-group-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
Map values = AgentConfiguration.getAgentGroupAttributes(adminSSOToken, realm, agentGroupName);
Set passwords = AgentConfiguration.getAttributesSchemaNames(amid, AttributeSchema.Syntax.PASSWORD);
if ((values != null) && !values.isEmpty()) {
StringBuilder buff = new StringBuilder();
// Used to generated a sorted list of property names for easier viewing
List<String> sortedKeys = new ArrayList<String>(values.keySet());
Collections.sort(sortedKeys);
for (String attrName : sortedKeys) {
if (passwords.contains(attrName)) {
buff.append(attrName).append("=********\n");
} else {
Set vals = (Set) values.get(attrName);
if (vals.isEmpty()) {
buff.append(attrName).append("=").append("\n");
} else {
for (Iterator j = vals.iterator(); j.hasNext(); ) {
String val = (String) j.next();
buff.append(attrName).append("=").append(val).append("\n");
}
}
}
}
if (outfile == null) {
outputWriter.printlnMessage(buff.toString());
} else {
writeToFile(outfile, buff.toString());
outputWriter.printlnMessage(getResourceString("show-agent-group-to-file"));
}
} else {
outputWriter.printlnMessage(getResourceString("show-agent-group-no-attributes"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_GROUP", params);
} catch (SMSException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("ShowAgentGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class ShowAgentTypes 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();
IOutput outputWriter = getOutputWriter();
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_TYPES", null);
Set agentTypes = AgentConfiguration.getAgentTypes();
if (!agentTypes.isEmpty()) {
for (Iterator i = agentTypes.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("show-agent-type-no-results"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_TYPES", null);
} catch (SMSException e) {
String[] args = { e.getMessage() };
debugError("ShowAgentTypes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_TYPES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { e.getMessage() };
debugError("ShowAgentTypes.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_TYPES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class UpdateAgent 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String agentName = getStringOptionValue(IArgument.AGENT_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
String[] params = { realm, agentName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentName, "agent did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
Object[] p = { agentName };
String msg = MessageFormat.format(getResourceString("update-agent-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
AgentConfiguration.updateAgent(adminSSOToken, realm, agentName, attributeValues, bSet);
outputWriter.printlnMessage(getResourceString("update-agent-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT", params);
} catch (IdRepoException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class UpdateAgentGroup 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
String[] params = { realm, agentGroupName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
if (!amid.isExists()) {
String[] args = { realm, agentGroupName, "agent group did not exist" };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
Object[] p = { agentGroupName };
String msg = MessageFormat.format(getResourceString("update-agent-group-does-not-exist"), p);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
AgentConfiguration.updateAgentGroup(adminSSOToken, realm, agentGroupName, attributeValues, bSet);
outputWriter.printlnMessage(getResourceString("update-agent-group-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT_GROUP", params);
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, e.getMessage() };
debugError("UpdateAgent.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.IOutput in project OpenAM by OpenRock.
the class AddAuthConfigurationEntry 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 realm = getStringOptionValue(IArgument.REALM_NAME);
String configName = getStringOptionValue(AuthOptions.AUTH_CONFIG_NAME);
String moduleName = getStringOptionValue(AuthOptions.AUTH_CONFIG_MODULE_NAME);
String criteria = getStringOptionValue(AuthOptions.AUTH_CONFIG_CRITERIA);
String options = getStringOptionValue(AuthOptions.AUTH_CONFIG_OPTIONS);
String[] params = { realm, configName, moduleName };
if (!POSSIBLE_CRITERIA.contains(criteria)) {
throw new CLIException(getResourceString("authentication-add-auth-config-entry-criteria.invalid"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
int pos = getPosition();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AUTH_CONFIG_ENTRY", params);
try {
AuthConfigurationEntry ae = new AuthConfigurationEntry(moduleName, criteria, options);
Set instanceNames = getInstanceNames(realm, adminSSOToken);
String instanceName = ae.getLoginModuleName();
if (!instanceNames.contains(instanceName)) {
Object[] p = { instanceName };
throw new CLIException(MessageFormat.format(getResourceString("authentication-add-auth-config-entry-not-found"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
List entries = getConfigEntries(realm, configName, adminSSOToken);
if (entries == null) {
entries = new ArrayList();
}
if ((pos == -1) || (pos >= entries.size())) {
entries.add(ae);
} else {
entries.add(pos, ae);
}
Map configData = new HashMap(2);
Set tmp = new HashSet(2);
String xml = AMAuthConfigUtils.authConfigurationEntryToXMLString(entries);
tmp.add(xml);
configData.put(AuthOptions.AUTH_CONFIG_ATTR, tmp);
IOutput outputWriter = getOutputWriter();
AMAuthConfigUtils.replaceNamedConfig(configName, 0, configData, realm, adminSSOToken);
outputWriter.printlnMessage(getResourceString("authentication-add-auth-config-entry-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_AUTH_CONFIG_ENTRY", params);
} catch (AMConfigurationException e) {
debugError("GetAuthConfigurationEntries.handleRequest", e);
String[] p = { realm, configName, moduleName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
debugError("GetAuthConfigurationEntries.handleRequest", e);
String[] p = { realm, configName, moduleName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
debugError("GetAuthConfigurationEntries.handleRequest", e);
String[] p = { realm, configName, moduleName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AUTH_CONFIG_ENTRY", p);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations