use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class Step3 method validateHostName.
/*
* a call is made to the OpenAM url entered in the browser. If
* the OpenAM server
* exists a <code>Map</code> of data will be returned which contains the
* information about the existing servers data store, including any
* replication ports if its embedded.
* Information to control the UI is returned in a JSON object of the form
* {
* "param1" : "value1",
* "param2" : "value2"
* }
* The JS on the browser will interpret the above and make the necessary
* changes to prompt the user for any more details required.
*/
public boolean validateHostName() {
StringBuffer sb = new StringBuffer();
String hostName = toString("hostName");
if (hostName == null) {
addObject(sb, "code", "100");
addObject(sb, "message", getLocalizedString("missing.required.field"));
} else {
// try to retrieve the remote OpenAM information
String admin = "amadmin";
String password = (String) getContext().getSessionAttribute(SessionAttributeNames.CONFIG_VAR_ADMIN_PWD);
try {
String dsType;
Map data = AMSetupUtils.getRemoteServerInfo(hostName, admin, password);
// data returned from existing OpenAM server
if (data != null && !data.isEmpty()) {
addObject(sb, "code", "100");
addObject(sb, "message", getLocalizedString("ok.string"));
setupDSParams(data);
String key = (String) data.get("enckey");
getContext().setSessionAttribute(SessionAttributeNames.ENCRYPTION_KEY, key);
getContext().setSessionAttribute(SessionAttributeNames.ENCLDAPUSERPASSWD, (String) data.get("ENCLDAPUSERPASSWD"));
// true for embedded, false for ODSEE
String embedded = (String) data.get(BootstrapData.DS_ISEMBEDDED);
addObject(sb, "embedded", embedded);
String host = (String) data.get(BootstrapData.DS_HOST);
if (embedded.equals("true")) {
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_HOST, getHostName());
addObject(sb, "configStoreHost", getHostName());
// set the multi embedded flag
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_VAR_DATA_STORE, SetupConstants.SMS_EMBED_DATASTORE);
getContext().setSessionAttribute(SessionAttributeNames.DS_EMB_REPL_FLAG, SetupConstants.DS_EMP_REPL_FLAG_VAL);
// get the existing replication ports if any
String replAvailable = (String) data.get(BootstrapData.DS_REPLICATIONPORT_AVAILABLE);
if (replAvailable == null) {
replAvailable = "false";
}
addObject(sb, "replication", replAvailable);
String existingRep = (String) data.get(BootstrapData.DS_REPLICATIONPORT);
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_REPL_PORT, existingRep);
addObject(sb, "replicationPort", existingRep);
String existingServerid = (String) data.get("existingserverid");
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_SERVER_ID, existingServerid);
addObject(sb, "existingserverid", existingServerid);
// dsmgr password is same as amadmin for embedded
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PWD, password);
} else {
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PORT, (String) data.get(BootstrapData.DS_PORT));
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_HOST, host);
addObject(sb, "configStoreHost", host);
String dsprot = (String) data.get(BootstrapData.DS_PROTOCOL);
String dsSSL = ("ldaps".equals(dsprot)) ? "SSL" : "SIMPLE";
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_SSL, dsSSL);
addObject(sb, "configStoreSSL", dsSSL);
String dspwd = (String) data.get(BootstrapData.DS_PWD);
getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PWD, Crypt.decode(dspwd, Crypt.getHardcodedKeyEncryptor()));
}
// set the replication ports pulled from the remote
// server in the session and pass back to the client
String existing = (String) data.get(SetupConstants.DS_EMB_REPL_ADMINPORT2);
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_PORT, existing);
addObject(sb, "existingPort", existing);
// set the configuration store port
String ds_existingStorePort = (String) data.get(BootstrapData.DS_PORT);
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_STORE_PORT, ds_existingStorePort);
addObject(sb, "existingStorePort", ds_existingStorePort);
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_HOST, host);
// set the configuration store host
getContext().setSessionAttribute(SessionAttributeNames.EXISTING_STORE_HOST, host);
addObject(sb, "existingStoreHost", host);
// set the configuration store port
getContext().setSessionAttribute(SessionAttributeNames.LOCAL_REPL_PORT, localRepPort);
}
} catch (ConfigurationException c) {
String code = c.getErrorCode();
String message = getLocalizedString(code);
if (code == null) {
code = "999";
message = c.getMessage();
}
addObject(sb, "code", code);
addObject(sb, "message", message);
} catch (ConfiguratorException c) {
String code = c.getErrorCode();
String message = getLocalizedString(code);
if (code == null) {
code = "999";
message = c.getMessage();
}
addObject(sb, "code", code);
addObject(sb, "message", message);
}
}
sb.append(" }");
writeToResponse(sb.toString());
setPath(null);
return false;
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class AgentsModelImpl method createAgentGroup.
/**
* Creates agent group.
*
* @param realmName Realm where agent group resides.
* @param name Name of agent group.
* @param type Type of agent group.
* @throws AMConsoleException if agent group cannot be created.
*/
public void createAgentGroup(String realmName, String name, String type) throws AMConsoleException {
String[] params = { realmName, name, type };
try {
logEvent("ATTEMPT_CREATE_AGENT_GROUP", params);
AgentConfiguration.createAgentGroup(getUserSSOToken(), realmName, name, type, AgentConfiguration.getDefaultValues(type, true));
logEvent("SUCCEED_CREATE_AGENT_GROUP", params);
} catch (ConfigurationException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
debug.warning("AgentsModelImpl.createAgentGroup", e);
throw new AMConsoleException(getErrorString(e));
} catch (SSOException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
debug.warning("AgentsModelImpl.createAgentGroup", e);
throw new AMConsoleException(getErrorString(e));
} catch (IdRepoException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
debug.warning("AgentsModelImpl.createAgentGroup", e);
throw new AMConsoleException(getErrorString(e));
} catch (SMSException e) {
String[] paramsEx = { realmName, name, type, getErrorString(e) };
logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
debug.warning("AgentsModelImpl.createAgentGroup", e);
throw new AMConsoleException(getErrorString(e));
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class AMSetupFilter method doFilter.
/**
* Redirects requests to configuration page if the product is not yet configured.
*
* @param req The HTTP request.
* @param resp The HTTP response.
* @param filterChain The filter chain.
* @throws IOException If configuration file cannot be read.
* @throws ServletException If there are errors in the servlet space.
*/
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
try {
if (setupManager.isCurrentConfigurationValid()) {
if (isSetupRequest(request.getRequestURI())) {
response.sendRedirect(createCleanUrl(request));
} else {
filterChain.doFilter(request, response);
}
} else {
if (isConfigStoreDown()) {
String redirectUrl = System.getProperty(Constants.CONFIG_STORE_DOWN_REDIRECT_URL);
if (StringUtils.isNotEmpty(redirectUrl)) {
response.sendRedirect(redirectUrl);
} else {
throw new ConfigurationException(CONFIG_STORE_DOWN_ERROR_CODE, null);
}
} else {
if (isPassthrough && isRequestForAllowedResource(resourcePath(request))) {
filterChain.doFilter(request, response);
} else if (isConfiguratorRequest(request.getRequestURI())) {
filterChain.doFilter(request, response);
} else {
String url = createCleanUrl(request);
if (hasWritePermissionOnUserHomeDirectory()) {
url += SETUP_URI;
} else {
url += NOWRITE_PERMISSION;
}
response.sendRedirect(url);
enablePassthrough();
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new ServletException("AMSetupFilter.doFilter", e);
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class AMSetupUtils method getRemoteServerInfo.
/**
* Obtains misc config data from a remote OpenAM server:
* <ul>
* <li>OpendDJ admin port</li>
* <li>config basedn</li>
* <li>replication ready flag</li>
* <li>OpenDJ replication port or OpenDJ suggested port</li>
* </ul>
*
* @param serverUrl URL string representing the remote OpenAM server.
* @param userId The admin user id on remote server, (only amadmin).
* @param password The admin password.
* @return A {@code Map} of config parameters.
* @throws ConfigurationException for the following error code:
* <ul>
* <li>400=Bad Request - user id/password param missing</li>
* <li>401=Unauthorized - invalid credentials</li>
* <li>405=Method Not Allowed - only POST is honored</li>
* <li>408=Request Timeout - requested timed out</li>
* <li>500=Internal Server Error</li>
* <li>701=File Not Found - incorrect deploy/server uri</li>
* <li>702=Connection Error - failed to connect</li>
* </ul>
*/
public static Map<String, String> getRemoteServerInfo(String serverUrl, String userId, String password) throws ConfigurationException {
HttpURLConnection connection = null;
try {
connection = openConnection(serverUrl + "/getServerInfo.jsp");
writeToConnection(connection, "IDToken1=" + URLEncoder.encode(userId, "UTF-8") + "&IDToken2=" + URLEncoder.encode(password, "UTF-8"));
// Remove any additional /n's from the result, often seen at the beginning of the response.
return BootstrapData.queryStringToMap(readFromConnection(connection).replace("\n", ""));
} catch (IllegalArgumentException e) {
debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
throw newConfigurationException("702");
} catch (IOException e) {
debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
if (e instanceof FileNotFoundException) {
throw newConfigurationException("701");
} else if (e instanceof SSLHandshakeException || e instanceof MalformedURLException || e instanceof UnknownHostException || e instanceof ConnectException) {
throw newConfigurationException("702");
} else {
int status = 0;
if (connection != null) {
try {
status = connection.getResponseCode();
} catch (Exception ignored) {
}
}
if (status == 400 || status == 401 || status == 405 || status == 408) {
throw newConfigurationException(String.valueOf(status));
} else {
throw new ConfiguratorException(e.getMessage());
}
}
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.
the class BootstrapCreator method update.
private void update(IDSConfigMgr dsCfg) throws ConfigurationException {
try {
String bootstrapString = getBootStrapURL(dsCfg);
String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
String file = baseDir + "/" + BootstrapData.BOOTSTRAP;
File f = new File(file);
boolean exist = f.exists();
boolean writable = exist && f.canWrite();
// make bootstrap writable if it is not
if (exist && !writable) {
f.setWritable(true);
Thread.sleep(3000);
}
writeToFile(file, bootstrapString);
// set permission to 400
if (!exist) {
if (isUnix) {
Runtime.getRuntime().exec("/bin/chmod 400 " + file);
}
} else {
// make it not writable if it was previously not writable.
if (!writable) {
f.setWritable(false);
}
}
} catch (InterruptedException e) {
throw new ConfigurationException(e.getMessage());
} catch (IOException e) {
throw new ConfigurationException(e.getMessage());
}
}
Aggregations