use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class RegisterServices method registerService.
private void registerService(String xml, SSOToken adminSSOToken) throws SSOException, SMSException, IOException {
ServiceManager serviceManager = new ServiceManager(adminSSOToken);
InputStream serviceStream = null;
try {
serviceStream = (InputStream) new ByteArrayInputStream(xml.getBytes());
serviceManager.registerServices(serviceStream);
} finally {
if (serviceStream != null) {
serviceStream.close();
}
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class ExportServiceConfiguration method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String outputFile = getStringOptionValue(IArgument.OUTPUT_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
FileOutputStream fout = null;
String[] param = { "tty" };
String[] paramException = { "tty", "" };
try {
if ((outputFile != null) && (outputFile.length() > 0)) {
fout = new FileOutputStream(outputFile);
param[0] = outputFile;
paramException[0] = outputFile;
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_EXPORT_SM_CONFIG_DATA", param);
ServiceManager sm = new ServiceManager(adminSSOToken);
AMEncryption encryptObj = new JCEEncryption();
((ConfigurableKey) encryptObj).setPassword(encryptSecret);
String resultXML = sm.toXML(encryptObj);
resultXML += "<!-- " + Hash.hash(encryptSecret) + " -->";
if (fout != null) {
fout.write(resultXML.getBytes("UTF-8"));
} else {
System.out.write(resultXML.getBytes("UTF-8"));
}
getOutputWriter().printlnMessage(getResourceString("export-service-configuration-succeeded"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_SM_CONFIG_DATA", param);
} catch (UnsupportedEncodingException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (Exception e) {
paramException[1] = e.getMessage();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException ioe) {
//ignored
}
}
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class LoadSchema 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();
boolean continueFlag = isOptionSet(IArgument.CONTINUE);
IOutput outputWriter = getOutputWriter();
List xmlFiles = (List) rc.getOption(IArgument.XML_FILE);
ServiceManager ssm = null;
try {
ssm = new ServiceManager(adminSSOToken);
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
CommandManager mgr = getCommandManager();
boolean bError = false;
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
String[] param = { CLIConstants.WEB_INPUT };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
loadSchemaXML(ssm, (String) xmlFiles.iterator().next());
outputWriter.printlnMessage(getResourceString("schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
} else {
for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
String file = (String) i.next();
String[] param = { file };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
loadSchema(ssm, file);
outputWriter.printlnMessage(getResourceString("schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
} catch (CLIException e) {
bError = true;
if (continueFlag) {
outputWriter.printlnError(getResourceString("schema-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
}
}
}
// if continue flag is on; throw cannot process exception
if (bError) {
throw new CLIException(getResourceString("one-or-more-services-not-added"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class UpdateService method handleRequest.
/**
* Updates service schema. Delete the service schema if it exists and
* load the schema.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
boolean continueFlag = isOptionSet(IArgument.CONTINUE);
IOutput outputWriter = getOutputWriter();
List xmlFiles = (List) rc.getOption(IArgument.XML_FILE);
ServiceManager ssm = null;
try {
ssm = new ServiceManager(adminSSOToken);
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
String strXML = (String) xmlFiles.iterator().next();
try {
List serviceNames = getServiceNames(SMSSchema.getXMLDocument(strXML, true));
deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
loadSchemaXML(ssm, strXML);
outputWriter.printlnMessage(getResourceString("service-updated"));
} catch (SMSException e) {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} else {
for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
String file = (String) i.next();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
List serviceNames = getServiceNames(SMSSchema.getXMLDocument(fis));
deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
loadSchema(ssm, file);
outputWriter.printlnMessage(getResourceString("service-updated"));
} catch (CLIException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
} catch (SMSException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (FileNotFoundException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ie) {
//igore if file input stream cannot be closed.
}
}
}
}
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class AccessControlModelImpl method getServiceNames.
private Set getServiceNames() {
if (serviceNames == null) {
SSOToken adminSSOToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
try {
ServiceManager sm = new ServiceManager(adminSSOToken);
serviceNames = sm.getServiceNames();
} catch (SSOException e) {
AMModelBase.debug.error("AccessControlModelImpl.getServiceNames", e);
} catch (SMSException e) {
AMModelBase.debug.error("AccessControlModelImpl.getServiceNames", e);
}
}
return serviceNames;
}
Aggregations