use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class RealmGetAssignedServices 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();
String realm = getStringOptionValue(IArgument.REALM_NAME);
boolean incMandatory = isOptionSet(IArgument.MANDATORY);
String strMandatory = (incMandatory) ? "include mandatory" : "exclude mandatory";
String[] params = { realm, strMandatory };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNED_SERVICES_OF_REALM", params);
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set serviceNames = ocm.getAssignedServices(incMandatory);
Set dynamicServiceNames = getAssignedDynamicServiceNames(adminSSOToken, realm);
if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
if ((serviceNames != null) && !serviceNames.isEmpty()) {
serviceNames.addAll(dynamicServiceNames);
} else {
serviceNames = dynamicServiceNames;
}
}
IOutput outputWriter = getOutputWriter();
if ((serviceNames != null) && !serviceNames.isEmpty()) {
String msg = getResourceString("realm-get-assigned-services-results");
outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-succeed"));
} else {
outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-no-services"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNED_SERVICES_OF_REALM", params);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignedServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignedServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmGetAssignedServices.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class DeleteSubConfiguration method deleteSubConfigToRoot.
private void deleteSubConfigToRoot(String serviceName, String subConfigName) throws CLIException {
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String[] params = { subConfigName, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SUB_CONFIGURATION", params);
try {
ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
ServiceConfig sc = scm.getGlobalConfig(null);
deleteSubConfig(sc, subConfigName);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_SUB_CONFIGURATION", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-sub-configuration-succeed"), (Object[]) params));
} catch (SSOException e) {
String[] args = { subConfigName, serviceName, e.getMessage() };
debugError("DeleteSubConfiguration.deleteSubConfigToRoot", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SUB_CONFIGURATION", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { subConfigName, serviceName, e.getMessage() };
debugError("DeleteSubConfiguration.deleteSubConfigToRoot", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SUB_CONFIGURATION", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ImportServiceConfiguration method getLDAPConnection.
private Connection getLDAPConnection() throws CLIException {
IOutput outputWriter = getOutputWriter();
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
}
try {
Connection conn;
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
ServerGroup sg = dsCfg.getServerGroup("sms");
if (sg != null) {
conn = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN).getConnection();
} else {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
}
return conn;
} catch (LDAPServiceException | LdapException e) {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class ImportServiceConfiguration 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 xmlFile = getStringOptionValue(IArgument.XML_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
try {
encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
} catch (CLIException clie) {
//There is no encryptSecret file
}
validateEncryptSecret(xmlFile, encryptSecret);
// disable notification
SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
// disable error debug messsage
SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
IOutput outputWriter = getOutputWriter();
try (Connection ldConnection = getLDAPConnection()) {
InitializeSystem initSys = CommandManager.initSys;
SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
loadLDIF(vendor, ldConnection);
String ouServices = "ou=services," + initSys.getRootSuffix();
if (this.isOuServicesExists(ssoToken, ouServices)) {
System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
value = value.trim();
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
deleteOuServicesDescendents(ssoToken, ouServices);
importData(xmlFile, encryptSecret, ssoToken);
}
} else {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
importData(xmlFile, encryptSecret, ssoToken);
}
} catch (SMSException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LdapException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LoginException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
} catch (InvalidAuthContextException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
}
use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.
the class LoadSchema method loadSchemaXML.
private void loadSchemaXML(ServiceManager ssm, String xml) throws CLIException {
ByteArrayInputStream bis = null;
try {
bis = new ByteArrayInputStream(xml.getBytes());
ssm.registerServices(bis);
} catch (SSOException e) {
String[] args = { CLIConstants.WEB_INPUT, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { CLIConstants.WEB_INPUT, e.getMessage() };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ie) {
//ignore if file input stream cannot be closed.
}
}
}
}
Aggregations