use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class CreateMetaDataTemplate method buildDescriptorTemplate.
private void buildDescriptorTemplate() throws CLIException {
Writer pw = null;
try {
boolean writeToFile = !isWebBased && (metadata != null) && (metadata.length() > 0);
if (writeToFile) {
pw = new PrintWriter(new FileWriter(metadata));
} else {
pw = new StringWriter();
}
String xml = CreateSAML2HostedProviderTemplate.buildMetaDataTemplate(entityID, getWorkflowParamMap(), protocol + "://" + host + ":" + port + deploymentURI);
pw.write(xml);
if (writeToFile) {
Object[] objs = { metadata };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-meta-template-created-descriptor-template"), objs));
}
} catch (SAML2MetaException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
Object[] objs = { metadata };
throw new CLIException(MessageFormat.format(getResourceString("cannot-write-to-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if ((pw != null) && (pw instanceof PrintWriter)) {
((PrintWriter) pw).close();
} else {
this.getOutputWriter().printlnMessage(((StringWriter) pw).toString());
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteCircleOfTrust method handleRequest.
/**
* Deletes a circle of trust.
*
* @param rc Request Context.
* @throws CLIException if unable to process this request.
*/
@Override
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
String[] params = { realm, cot };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_COT", params);
try {
CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
cotManager.deleteCircleOfTrust(realm, cot);
Object[] obj = { cot };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("delete-circle-of-trust-succeeded"), obj));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_COT", params);
} catch (COTException e) {
debugWarning("DeleteCircleOfTrust.handleRequest", e);
String[] args = { realm, cot, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_COT", args);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ShowSite method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
@Override
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String siteName = getStringOptionValue(IArgument.SITE_NAME);
String[] params = { siteName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE", params);
if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
String primaryURL = SiteConfiguration.getSitePrimaryURL(adminSSOToken, siteName);
Set failoverURLs = SiteConfiguration.getSiteSecondaryURLs(adminSSOToken, siteName);
String siteId = SiteConfiguration.getSiteID(adminSSOToken, siteName);
Object[] args = { primaryURL };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-primaryURL"), args));
if ((failoverURLs != null) && !failoverURLs.isEmpty()) {
outputWriter.printlnMessage(getResourceString("show-site-secondaryURL"));
for (Iterator i = failoverURLs.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("show-site-no-secondaryURL"));
}
outputWriter.printlnMessage("");
args[0] = siteId;
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-ID"), args));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-no-exists"), (Object[]) params));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE", params);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSite.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSite.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ShowSiteMembers method handleRequest.
/**
* Display members of a site.
*
* @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 siteName = getStringOptionValue(IArgument.SITE_NAME);
String[] params = { siteName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE_MEMBERS", params);
IOutput outputWriter = getOutputWriter();
try {
Set members = SiteConfiguration.listServers(adminSSOToken, siteName);
if ((members != null) && !members.isEmpty()) {
for (Iterator i = members.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("show-site-members-no-members"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE_MEMBERS", params);
} catch (ConfigurationException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { siteName, e.getMessage() };
debugError("ShowSiteMembers.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class AddCircleOfTrustMembers method handleRequest.
/**
* Adds member to a circle of trust.
*
* @param rc Request Context.
* @throws CLIException if unable to process this request.
*/
@Override
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
spec = FederationManager.getIDFFSubCommandSpecification(rc);
entityID = getStringOptionValue(FedCLIConstants.ARGUMENT_ENTITY_ID);
String[] params = { realm, entityID, cot, spec };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_COT_MEMBER", params);
try {
CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
cotManager.addCircleOfTrustMember(realm, cot, spec, entityID);
Object[] objs = { spec, cot, entityID, realm };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("add-circle-of-trust-member-succeeded"), objs));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_COT_MEMBER", params);
} catch (COTException e) {
debugWarning("AddCircleOfTrustMembers.handleRequest", e);
if (e instanceof L10NMessage) {
String[] args = { realm, entityID, cot, spec, ((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()) };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
throw new CLIException(((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} else {
String[] args = { realm, entityID, cot, spec, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
}
Aggregations