use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class BootstrapCreator method getBootStrapURL.
/**
* Returns the bootstrap url.
*
* @param dsCfg instance of the <code>IDSConfigMgr</code> containing
* the connection information to the config store.
* @exception ConfigurationException if there is an error and cannot
* obtain the bootstrap URL. This may be due to connection error.
*/
public String getBootStrapURL(IDSConfigMgr dsCfg) throws ConfigurationException {
String bootstrapStr = null;
try {
ServerGroup sg = dsCfg.getServerGroup("sms");
ServerGroup defaultGroup = dsCfg.getServerGroup("default");
ServerInstance svrCfg;
if (sg == null) {
sg = defaultGroup;
svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
} else {
svrCfg = sg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
}
ServerInstance userInstance = defaultGroup.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
String dsameUserName = userInstance.getAuthID();
String dsameUserPwd = JCECrypt.encode(userInstance.getPasswd());
String connDN = svrCfg.getAuthID();
String connPwd = JCECrypt.encode(svrCfg.getPasswd());
String rootSuffix = svrCfg.getBaseDN();
Collection serverList = sg.getServersList();
StringBuilder bootstrap = new StringBuilder();
for (Iterator i = serverList.iterator(); i.hasNext(); ) {
Server serverObj = (Server) i.next();
Server.Type connType = serverObj.getConnectionType();
String proto = (connType.equals(Server.Type.CONN_SIMPLE)) ? "ldap" : "ldaps";
String url = StringUtils.strReplaceAll(template, "@DS_PROTO@", proto);
String host = serverObj.getServerName() + ":" + serverObj.getPort();
url = StringUtils.strReplaceAll(url, "@DS_HOST@", host);
url = StringUtils.strReplaceAll(url, "@INSTANCE_NAME@", URLEncoder.encode(SystemProperties.getServerInstanceName(), "UTF-8"));
url = StringUtils.strReplaceAll(url, "@DSAMEUSER_NAME@", URLEncoder.encode(dsameUserName, "UTF-8"));
url = StringUtils.strReplaceAll(url, "@DSAMEUSER_PWD@", URLEncoder.encode(dsameUserPwd, "UTF-8"));
url = StringUtils.strReplaceAll(url, "@BASE_DN@", URLEncoder.encode(rootSuffix, "UTF-8"));
url = StringUtils.strReplaceAll(url, "@BIND_DN@", URLEncoder.encode(connDN, "UTF-8"));
url = StringUtils.strReplaceAll(url, "@BIND_PWD@", URLEncoder.encode(connPwd, "UTF-8"));
bootstrap.append(url).append("\n");
}
bootstrapStr = bootstrap.toString();
} catch (IOException e) {
throw new ConfigurationException(e.getMessage());
}
return bootstrapStr;
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class BootstrapCreator method updateBootstrap.
public static void updateBootstrap() throws ConfigurationException {
try {
DSConfigMgrBase dsCfg = new DSConfigMgrBase();
dsCfg.parseServiceConfigXML();
instance.update(dsCfg);
} catch (XMLException e) {
throw new ConfigurationException(e.getMessage());
} catch (SMSException e) {
throw new ConfigurationException(e.getMessage());
} catch (SSOException e) {
throw new ConfigurationException(e.getMessage());
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class AgentsModelImpl method createAgentLocal.
/**
* Creates localized agent.
*
* @param realmName Realm where agent resides.
* @param name Name of agent.
* @param type Type of agent.
* @param password Password of agent.
* @param agentURL Agent URL.
* @throws AMConsoleException if agent cannot be created.
*/
public void createAgentLocal(String realmName, String name, String type, String password, String agentURL) throws AMConsoleException {
String[] params = { realmName, name, type };
try {
logEvent("ATTEMPT_CREATE_AGENT", params);
Map map = AgentConfiguration.getDefaultValues(type, false);
Set set = new HashSet(2);
map.put(AgentConfiguration.ATTR_NAME_PWD, set);
set.add(password);
Set newset = new HashSet(2);
newset.add(AgentConfiguration.VAL_CONFIG_REPO_LOCAL);
map.put(AgentConfiguration.ATTR_CONFIG_REPO, newset);
AgentConfiguration.createAgentLocal(getUserSSOToken(), realmName, name, type, map, agentURL);
logEvent("SUCCEED_CREATE_AGENT", params);
} catch (ConfigurationException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
debug.warning("AgentsModelImpl.createAgent", e);
throw new AMConsoleException(getErrorString(e));
} catch (MalformedURLException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
debug.warning("AgentsModelImpl.createAgent", e);
throw new AMConsoleException(getErrorString(e));
} catch (SSOException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
debug.warning("AgentsModelImpl.createAgent", e);
throw new AMConsoleException(getErrorString(e));
} catch (IdRepoException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
debug.warning("AgentsModelImpl.createAgent", e);
throw new AMConsoleException(getErrorString(e));
} catch (SMSException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
debug.warning("AgentsModelImpl.createAgent", e);
throw new AMConsoleException(getErrorString(e));
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class ImportServer 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);
String xmlFile = getStringOptionValue(IArgument.XML_FILE);
String[] params = { serverName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IMPORT_SERVER", params);
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
ServerConfiguration.importServerInstance(adminSSOToken, serverName, xmlFile);
outputWriter.printlnMessage(getResourceString("import-server-succeeded"));
} else {
outputWriter.printlnMessage(getResourceString("import-server-already-exists"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IMPORT_SERVER", params);
} catch (ConfigurationException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (ParserConfigurationException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SAXException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("CreateServer.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class UpdateServerConfig 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);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
encryptPasswordAttributes(attributeValues);
String[] params = { serverName };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_SERVER_CONFIG", params);
if (serverName.equals(DEFAULT_SVR_CONFIG)) {
try {
ServerConfiguration.setServerInstance(adminSSOToken, ServerConfiguration.DEFAULT_SERVER_CONFIG, attributeValues);
} catch (UnknownPropertyNameException ex) {
outputWriter.printlnMessage(ex.getL10NMessage(getCommandManager().getLocale()));
outputWriter.printlnMessage("");
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-succeeded"), (Object[]) params));
} else {
if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
try {
ServerConfiguration.setServerInstance(adminSSOToken, serverName, attributeValues);
} catch (UnknownPropertyNameException ex) {
outputWriter.printlnMessage(getResourceString("update-server-config-unknown"));
outputWriter.printlnMessage("");
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-succeeded"), (Object[]) params));
} else {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-does-not-exists"), (Object[]) params));
}
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_SERVER_CONFIG", params);
} catch (ConfigurationException e) {
String[] args = { serverName, e.getMessage() };
debugError("UpdateServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
String[] args = { serverName, e.getMessage() };
debugError("UpdateServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { serverName, e.getMessage() };
debugError("UpdateServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serverName, e.getMessage() };
debugError("UpdateServerConfig.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations