Class AMSetupUtils


  • public final class AMSetupUtils
    extends Object
    Utility methods that are used by various setup/startup classes.
    Since:
    13.0.0
    • Method Detail

      • readFile

        public static String readFile​(jakarta.servlet.ServletContext servletContext,
                                      String file)
                               throws IOException
        Reads the contents of the provided File.

        The file is located using the provided ServletContext.

        Parameters:
        servletContext - The ServletContext to use to find the file.
        file - The File to 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:
        true if in use, false if 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 Map of 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 an InputStream.
        Parameters:
        servletContext - The ServletContext to use to find the file.
        file - The File to retrieve.
        Returns:
        An InputStream of the files contents.