AMSetupUtils.java revision cfba646ddfa9d543f0c40e4c7788c65b4a24b34d
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
/**
*
* @since 13.0.0
*/
public final class AMSetupUtils {
private AMSetupUtils() {
}
/**
* Reads the contents of the provided {@code File}.
*
* <p>The file is located using the provided {@code ServletContext}.</p>
*
* @param servletContext The {@code ServletContext} to use to find the file.
* @param file The {@code File} to read.
* @return The contents of the file.
* @throws IOException If the file could not be found or read.
*/
try {
}
} finally {
}
}
/**
* Creates a new secure random string.
*
* @return A secure random string.
*/
public static String getRandomString() {
try {
byte[] bytes = new byte[24];
} catch (Exception e) {
}
}
/**
* Returns the next unused port on a given host.
*
* @param hostname The name of the host, (eg localhost).
* @param start The starting port number to check, (eg 389).
* @param increment The port number increments to check, (eg 1000).
* @return The next available port number, or -1 if no available ports found.
*/
if (isPortInUse(hostname, i)) {
return i;
}
}
return -1;
}
/**
* Checks whether the given host and port is currently under use.
*
* @param hostname The name of the host, (eg localhost).
* @param port The port number to check.
* @return {@code true} if in use, {@code false} if not in use.
*/
try {
} catch (NullPointerException e) {
return false;
}
}
try {
serverSocket = new ServerSocket();
return false;
} catch (IOException e) {
return true;
} finally {
if (serverSocket != null) {
try {
} catch (IOException ignored) {
}
}
}
}
try {
return true;
} catch (IOException e) {
return false;
} finally {
try {
} catch (IOException ignored) {
}
}
}
}
/**
* 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>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>702=Connection Error - failed to connect</li>
* </ul>
*/
public static Map<String, String> getRemoteServerInfo(String serverUrl, String userId, String password)
throws ConfigurationException {
try {
} catch (IllegalArgumentException e) {
throw newConfigurationException("702");
} catch (IOException 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 {
}
}
} else {
throw new ConfiguratorException(e.getMessage());
}
}
} finally {
if (connection != null) {
}
}
}
return true;
}
});
}
return connection;
}
connection.setDoOutput(true);
try {
} finally {
}
}
}
}
/**
* Gets the file contents as an {@code InputStream}.
*
* @param servletContext The {@code ServletContext} to use to find the file.
* @param file The {@code File} to retrieve.
* @return An {@code InputStream} of the files contents.
*/
if (servletContext == null) {
}
} else {
}
}
}