Package com.sun.identity.setup
Class AMSetupUtils
- java.lang.Object
-
- com.sun.identity.setup.AMSetupUtils
-
public final class AMSetupUtils extends Object
Utility methods that are used by various setup/startup classes.- Since:
- 13.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetFirstUnusedPort(String hostname, int start, int increment)Returns the next unused port on a given host.static StringgetRandomString()Creates a new secure random string.static Map<String,String>getRemoteServerInfo(String serverUrl, String userId, String password)Obtains misc config data from a remote OpenAM server: OpendDJ admin port config basedn replication ready flag OpenDJ replication port or OpenDJ suggested portstatic InputStreamgetResourceAsStream(jakarta.servlet.ServletContext servletContext, String file)Gets the file contents as anInputStream.static booleanisPortInUse(String hostname, int port)Checks whether the given host and port is currently under use.static StringreadFile(jakarta.servlet.ServletContext servletContext, String file)Reads the contents of the providedFile.
-
-
-
Method Detail
-
readFile
public static String readFile(jakarta.servlet.ServletContext servletContext, String file) throws IOException
Reads the contents of the providedFile.The file is located using the provided
ServletContext.- Parameters:
servletContext- TheServletContextto use to find the file.file- TheFileto read.- Returns:
- The contents of the file.
- Throws:
IOException- If the file could not be found or read.
-
getRandomString
public static String getRandomString()
Creates a new secure random string.- Returns:
- A secure random string.
-
getFirstUnusedPort
public static int getFirstUnusedPort(String hostname, int start, int increment)
Returns the next unused port on a given host.- Parameters:
hostname- The name of the host, (eg localhost).start- The starting port number to check, (eg 389).increment- The port number increments to check, (eg 1000).- Returns:
- The next available port number, or -1 if no available ports found.
-
isPortInUse
public static boolean isPortInUse(String hostname, int port)
Checks whether the given host and port is currently under use.- Parameters:
hostname- The name of the host, (eg localhost).port- The port number to check.- Returns:
trueif in use,falseif not in use.
-
getRemoteServerInfo
public static Map<String,String> getRemoteServerInfo(String serverUrl, String userId, String password) throws ConfigurationException
Obtains misc config data from a remote OpenAM server:- OpendDJ admin port
- config basedn
- replication ready flag
- OpenDJ replication port or OpenDJ suggested port
- Parameters:
serverUrl- URL string representing the remote OpenAM server.userId- The admin user id on remote server, (only amadmin).password- The admin password.- Returns:
- A
Mapof config parameters. - Throws:
ConfigurationException- for the following error code:- 400=Bad Request - user id/password param missing
- 401=Unauthorized - invalid credentials
- 405=Method Not Allowed - only POST is honored
- 408=Request Timeout - requested timed out
- 500=Internal Server Error
- 701=File Not Found - incorrect deploy/server uri
- 702=Connection Error - failed to connect
-
getResourceAsStream
public static InputStream getResourceAsStream(jakarta.servlet.ServletContext servletContext, String file)
Gets the file contents as anInputStream.- Parameters:
servletContext- TheServletContextto use to find the file.file- TheFileto retrieve.- Returns:
- An
InputStreamof the files contents.
-
-