use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RemoveSiteFailoverURLs 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
List secondaryURLs = (List) rc.getOption(IArgument.SECONDARY_URLS);
String[] params = { siteName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SITE_FAILOVER_URLS", params);
if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
SiteConfiguration.removeSiteSecondaryURLs(adminSSOToken, siteName, secondaryURLs);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-site-secondary-urls-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-site-secondary-urls-no-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SITE_FAILOVER_URLS", params);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("RemoveSiteFailoverURLs.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SITE_FAILOVER_URLS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("RemoveSiteFailoverURLs.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SITE_FAILOVER_URLS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class CreateServer 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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
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());
}
Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
String serverconfigxml = CLIUtil.getFileContent(getCommandManager(), getStringOptionValue(SERVER_CONFIG_XML_FILE));
String[] params = { serverName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_SERVER", params);
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
ServerConfiguration.createServerInstance(adminSSOToken, serverName, attributeValues, serverconfigxml);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-already-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_SERVER", params);
} catch (UnknownPropertyNameException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteServer 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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
String[] params = { serverName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SERVER", params);
if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
ServerConfiguration.deleteServerInstance(adminSSOToken, serverName);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-server-config-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-server-config-dont-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_SERVER", params);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("DeleteServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("DeleteServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class GetServerConfigXML method handleRequest.
/**
* Returns Server Configuration XML.
*
* @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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
String outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
IOutput outputWriter = getOutputWriter();
try {
String[] params = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SERVER_CONFIG_XML", params);
String xml = ServerConfiguration.getServerConfigXML(adminSSOToken, serverName);
if ((xml != null) && (xml.length() > 0)) {
if ((outfile != null) && (outfile.length() > 0)) {
CLIUtil.writeToFile(outfile, xml);
} else {
outputWriter.printlnMessage(xml);
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-serverconfig-xml-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(getResourceString("get-server-config-xml-no-result-no-results"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SERVER_CONFIG_XML", params);
} catch (IOException e) {
String[] args = { serverName, e.getMessage() };
debugError("GetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("GetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("GetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RemovePrivileges 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);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
List privileges = (List) rc.getOption(IArgument.PRIVILEGES);
IdType idType = convert2IdType(type);
String[] params = { realm, type, idName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_REMOVE_PRIVILEGES", params);
DelegationManager mgr = new DelegationManager(adminSSOToken, realm);
Set privilegeObjects = mgr.getPrivileges();
AMIdentity amid;
if (idType.equals(IdType.ROLE) && idName.equalsIgnoreCase(ALL_AUTHENTICATED_USERS)) {
//realm needs to be /, see DelegationPolicyImpl#privilegeToPolicy implementation
amid = new AMIdentity(adminSSOToken, idName, idType, "/", null);
//do not check the existense of all authenticated users role as it would fail
} else {
amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
}
String uid = amid.getUniversalId();
for (Iterator i = privileges.iterator(); i.hasNext(); ) {
String name = (String) i.next();
DelegationPrivilege dp = getDelegationPrivilege(name, privilegeObjects);
boolean removed = false;
if (dp != null) {
Set subjects = dp.getSubjects();
if (subjects.contains(uid)) {
subjects.remove(uid);
mgr.addPrivilege(dp);
removed = true;
}
}
if (!removed) {
String[] args = { idName, name };
String msg = MessageFormat.format(getResourceString("delegation-does-not-have-privilege"), (Object[]) args);
throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-remove-privileges-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_REMOVE_PRIVILEGES", params);
} catch (DelegationException e) {
String[] args = { realm, type, idName, e.getMessage() };
debugError("RemovePrivileges.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_PRIVILEGES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, e.getMessage() };
debugError("RemovePrivileges.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_PRIVILEGES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations