use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ShowAgent method writeToFile.
private void writeToFile(String outfile, String content) throws CLIException {
FileOutputStream fout = null;
PrintWriter pwout = null;
try {
fout = new FileOutputStream(outfile, true);
pwout = new PrintWriter(fout, true);
pwout.write(content);
pwout.flush();
} catch (FileNotFoundException e) {
debugError("ShowAgent.writeToFile", e);
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
} catch (SecurityException e) {
debugError("ShowAgent.writeToFile", e);
throw new CLIException(e, ExitCodes.IO_EXCEPTION);
} finally {
try {
if (fout != null) {
fout.close();
}
if (pwout != null) {
pwout.close();
}
} catch (IOException ex) {
//do nothing
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteAgents 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);
List agentNames = (List) rc.getOption(IArgument.AGENT_NAMES);
String file = getStringOptionValue(IArgument.FILE);
if (agentNames == null) {
agentNames = new ArrayList();
}
if (file != null) {
agentNames.addAll(AttributeValues.parseValues(file));
}
if (agentNames.isEmpty()) {
throw new CLIException(getResourceString("missing-agent-names"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
String displayableNames = tokenize(agentNames);
String[] params = { realm, displayableNames };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AGENTS", params);
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
Set setDelete = new HashSet();
for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
String name = (String) i.next();
AMIdentity amid = new AMIdentity(adminSSOToken, name, IdType.AGENTONLY, realm, null);
setDelete.add(amid);
}
amir.deleteIdentities(setDelete);
IOutput outputWriter = getOutputWriter();
outputWriter.printlnMessage(getResourceString("delete-agent-succeeded"));
for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage(" " + (String) i.next());
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_AGENTS", params);
} catch (IdRepoException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ListAgents 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 patternType = getStringOptionValue(IArgument.AGENT_TYPE);
String filter = getStringOptionValue(IArgument.FILTER);
if (patternType == null) {
patternType = "";
}
if ((filter == null) || (filter.length() == 0)) {
filter = "*";
}
String[] params = { realm, patternType, filter };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENTS", params);
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
IdSearchResults isr = amir.searchIdentities(IdType.AGENTONLY, filter, new IdSearchControl());
Set results = isr.getSearchResults();
if ((results != null) && !results.isEmpty()) {
for (Iterator i = results.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
if (!matchType(amid, patternType)) {
i.remove();
}
}
}
if ((results != null) && !results.isEmpty()) {
for (Iterator i = results.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
Object[] args = { amid.getName(), amid.getUniversalId() };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-agent-results"), args));
}
} else {
outputWriter.printlnMessage(getResourceString("search-agent-no-entries"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENTS", params);
} catch (IdRepoException e) {
String[] args = { realm, patternType, filter, e.getMessage() };
debugError("ListAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, patternType, filter, e.getMessage() };
debugError("ListAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AddAgentsToGroup 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);
List agentNames = rc.getOption(IArgument.AGENT_NAMES);
String[] params = { realm, agentGroupName, "" };
String agentName = "";
try {
AMIdentity amidGroup = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
agentName = (String) i.next();
params[2] = agentName;
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AGENT_TO_GROUP", params);
AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
AgentConfiguration.AddAgentToGroup(amidGroup, amid);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_AGENT_TO_GROUP", params);
}
if (agentNames.size() > 1) {
outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded-pural"));
} else {
outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded"));
}
} catch (IdRepoException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, agentGroupName, agentName, e.getMessage() };
debugError("AddAgentsToGroup.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteAgentGroups 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);
List names = (List) rc.getOption(IArgument.AGENT_GROUP_NAMES);
String file = getStringOptionValue(IArgument.FILE);
if (names == null) {
names = new ArrayList();
}
if (file != null) {
names.addAll(AttributeValues.parseValues(file));
}
if (names.isEmpty()) {
throw new CLIException(getResourceString("missing-agent-group-names"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
String displayableNames = tokenize(names);
String[] params = { realm, displayableNames };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AGENT_GROUPS", params);
try {
Set setDelete = new HashSet();
for (Iterator i = names.iterator(); i.hasNext(); ) {
String name = (String) i.next();
AMIdentity amid = new AMIdentity(adminSSOToken, name, IdType.AGENTGROUP, realm, null);
setDelete.add(amid);
}
AgentConfiguration.deleteAgentGroups(adminSSOToken, realm, setDelete);
IOutput outputWriter = getOutputWriter();
outputWriter.printlnMessage(getResourceString("delete-agent-group-succeeded"));
for (Iterator i = names.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage(" " + (String) i.next());
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_AGENT_GROUPS", params);
} catch (IdRepoException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, displayableNames, e.getMessage() };
debugError("DeleteAgentGroups.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AGENT_GROUPS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations