use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ExportMetaData method runIDFFExportMetaSign.
private void runIDFFExportMetaSign() throws CLIException {
PrintWriter pw = null;
String out = (isWebBase) ? "web" : metadata;
Object[] objs = { out };
try {
IDFFMetaManager metaManager = new IDFFMetaManager(ssoToken);
com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement descriptor = metaManager.getEntityDescriptor(realm, entityID);
if (descriptor == null) {
Object[] objs2 = { entityID, realm };
throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-descriptor-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig(realm, entityID);
IDPDescriptorConfigElement idpConfig = metaManager.getIDPDescriptorConfig(realm, entityID);
Document doc = null;
/*
* TODO: Signing
* Document doc = SAML2MetaSecurityUtils.sign(
descriptor, spConfig, idpConfig);
*/
if (doc == null) {
runIDFFExportMeta();
return;
} else {
String xmlstr = XMLUtils.print(doc);
if (isWebBase) {
getOutputWriter().printlnMessage(xmlstr);
} else {
pw = new PrintWriter(new FileWriter(metadata));
pw.print(xmlstr);
}
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-descriptor-succeeded"), objs));
}
} catch (IDFFMetaException e) {
debugError("ExportMetaData.runIDFFExportMetaSign", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
debugError("ExportMetaData.runIDFFExportMetaSign", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (pw != null) {
pw.close();
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ExportMetaData method runExportExtended.
private void runExportExtended() throws CLIException {
OutputStream os = null;
String out = (isWebBase) ? "web" : extendedData;
Object[] objs = { out };
Object[] objs2 = { entityID, realm };
try {
SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
EntityConfigElement config = metaManager.getEntityConfig(realm, entityID);
if (config == null) {
throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-config-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
if (isWebBase) {
os = new ByteArrayOutputStream();
} else {
os = new FileOutputStream(extendedData);
}
SAML2MetaUtils.convertJAXBToOutputStream(config, os);
if (isWebBase) {
getOutputWriter().printlnMessage(os.toString());
}
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-config-succeeded"), objs));
} catch (SAML2MetaException e) {
debugError("ExportMetaData.runExportExtended", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (FileNotFoundException e) {
debugWarning("ExportMetaData.runExportExtended", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (JAXBException e) {
debugWarning("ExportMetaData.runExportExtended", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IllegalArgumentException e) {
debugWarning("ExportMetaData.runExportExtended", e);
throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid-config"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
// ignore
}
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ExportMetaData method runExportMetaSign.
private void runExportMetaSign() throws CLIException {
PrintWriter pw = null;
String out = (isWebBase) ? "web" : metadata;
Object[] objs = { out };
try {
SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
EntityDescriptorElement descriptor = metaManager.getEntityDescriptor(realm, entityID);
if (descriptor == null) {
Object[] objs2 = { entityID, realm };
throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-descriptor-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
Document doc = SAML2MetaSecurityUtils.sign(realm, descriptor);
if (doc == null) {
runExportMeta();
return;
} else {
String xmlstr = XMLUtils.print(doc);
xmlstr = workaroundAbstractRoleDescriptor(xmlstr);
if (isWebBase) {
getOutputWriter().printlnMessage(xmlstr);
} else {
pw = new PrintWriter(new FileWriter(metadata));
pw.print(xmlstr);
}
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-descriptor-succeeded"), objs));
}
} catch (SAML2MetaException e) {
debugError("ExportMetaData.runExportMetaSign", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (JAXBException jaxbe) {
Object[] objs3 = { entityID, realm };
throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid_descriptor"), objs3), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
debugError("ExportMetaData.runExportMetaSign", e);
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (pw != null) {
pw.close();
}
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ListSites 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_LIST_SITES", null);
Set sites = SiteConfiguration.getSites(adminSSOToken);
if ((sites != null) && !sites.isEmpty()) {
for (Iterator i = sites.iterator(); i.hasNext(); ) {
outputWriter.printlnMessage((String) i.next());
}
} else {
outputWriter.printlnMessage(getResourceString("list-sites-no-instances"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_SITES", null);
} catch (SSOException e) {
String[] args = { e.getMessage() };
debugError("ListSites.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_SITES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { e.getMessage() };
debugError("ListSites.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_SITES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RemoveServerConfig 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);
List propertyNames = rc.getOption(IArgument.PROPERTY_NAMES);
try {
String[] params = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SERVER_CONFIG", params);
if (serverName.equals(DEFAULT_SVR_CONFIG)) {
ServerConfiguration.removeServerConfiguration(adminSSOToken, ServerConfiguration.DEFAULT_SERVER_CONFIG, propertyNames);
} else {
if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
ServerConfiguration.removeServerConfiguration(adminSSOToken, serverName, propertyNames);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-server-config-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-server-config-does-not-exists"), (Object[]) params));
}
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SERVER_CONFIG", params);
} catch (IOException e) {
String[] args = { serverName, e.getMessage() };
debugError("RemoveServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("RemoveServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("RemoveServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations