use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class BulkFederation method getEntityRoleAndIdIDFF.
private void getEntityRoleAndIdIDFF() throws CLIException {
try {
IDFFMetaManager idffMgr = new IDFFMetaManager(ssoToken);
String role = idffMgr.getProviderRoleByMetaAlias(metaAlias);
if (role == null) {
Object[] param = { metaAlias };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
isIDP = role.equals(IFSConstants.IDP);
localEntityId = idffMgr.getEntityIDByMetaAlias(metaAlias);
} catch (IDFFMetaException e) {
debugError("BulkFederation.getEntityRoleAndIdIDFF", e);
Object[] param = { metaAlias };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class BulkFederation method validateFiles.
/*
* Checks if the input file exists
* Checks if the output file is writable
* Returns a handle to the output file writer.
*/
private BufferedWriter validateFiles() throws CLIException {
File input = new File(userIdMappingFileName);
if (!input.exists()) {
Object[] param = { userIdMappingFileName };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-infile-do-not-exists"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
File output = new File(outFile);
if (output.exists()) {
Object[] param = { outFile };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-outfile-exists"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
try {
output.createNewFile();
if (!output.canWrite()) {
Object[] param = { outFile };
throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-outfile-cannot-write"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
BufferedWriter out = new BufferedWriter(new FileWriter(output));
out.write(HEADER_LOCAL + localEntityId);
out.newLine();
out.write(HEADER_REMOTE + remoteEntityId);
out.newLine();
String role = (isIDP) ? "IDP" : "SP";
out.write(HEADER_ROLE + role);
out.newLine();
if (spec.equals(FedCLIConstants.IDFF_SPECIFICATION)) {
out.write(HEADER_SPEC + FedCLIConstants.IDFF_SPECIFICATION);
} else {
out.write(HEADER_SPEC + FedCLIConstants.SAML2_SPECIFICATION);
}
out.newLine();
return out;
} catch (IOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ServerConfigBase 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);
String serverName = getStringOptionValue(IArgument.SERVER_NAME);
if ((serverName != null) && (serverName.trim().length() > 0) && !serverName.equals(DEFAULT_SVR_CONFIG)) {
try {
URL url = new URL(serverName);
if (url.getPort() == -1) {
throw new CLIException(getResourceString("server-config-port-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
if (url.getPath().length() == 0) {
throw new CLIException(getResourceString("server-config-uri-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (MalformedURLException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class SetServerConfigXML method handleRequest.
/**
* Set 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 xmlFile = getStringOptionValue(IArgument.XML_FILE);
IOutput outputWriter = getOutputWriter();
try {
String[] params = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SERVER_CONFIG_XML", params);
String xml = xmlFile;
boolean isWebEnabled = getCommandManager().webEnabled();
if (!isWebEnabled) {
xml = CLIUtil.getFileContent(getCommandManager(), xmlFile);
}
ServerConfiguration.setServerConfigXML(adminSSOToken, serverName, xml);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-serverconfig-xml-succeeded"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SERVER_CONFIG_XML", params);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("SetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SERVER_CONFIG_XML", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { serverName, e.getMessage() };
debugError("SetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SERVER_CONFIG_XML", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("SetServerConfigXML.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_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 SetSiteFailoverURLs 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_SET_SITE_FAILOVER_URLS", params);
if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
SiteConfiguration.setSiteSecondaryURLs(adminSSOToken, siteName, secondaryURLs);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-secondary-urls-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-secondary-urls-no-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SITE_FAILOVER_URLS", params);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("SetSiteFailoverURLs.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ConfigurationException e) {
String[] args = { siteName, e.getMessage() };
debugError("SetSiteFailoverURLs.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("SetSiteFailoverURLs.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations