Class ClientUtil


  • public class ClientUtil
    extends java.lang.Object
    ClientUtil allows a user to connect to a Repository Server and obtain its handle.
    • Method Detail

      • setClientAuthenticator

        public static void setClientAuthenticator​(ClientAuthenticator authenticator)
        Set client authenticator
        Parameters:
        authenticator -
      • getClientAuthenticator

        public static ClientAuthenticator getClientAuthenticator()
        Get the currently installed client authenticator. If one has not been installed, this will trigger the installation of a default instance.
        Returns:
        current client authenticator
      • getRepositoryServer

        public static RepositoryServerAdapter getRepositoryServer​(java.lang.String host,
                                                                  int port)
        Connect to a Repository Server and obtain a handle to it. Based upon the server authentication requirements, the user may be prompted for a password via a Swing dialog. If a previous connection attempt to this server failed, the adapter may be returned in a disconnected state.
        Parameters:
        host - server name or address
        port - server port, 0 indicates that default port should be used.
        Returns:
        repository server adapter
        Throws:
        javax.security.auth.login.LoginException - thrown if server fails to authenticate user or general access is denied.
      • getRepositoryServer

        public static RepositoryServerAdapter getRepositoryServer​(java.lang.String host,
                                                                  int port,
                                                                  boolean forceConnect)
        Connect to a Repository Server and obtain a handle to it. Based upon the server authentication requirements, the user may be prompted for a password via a Swing dialog.
        Parameters:
        host - server name or address
        port - server port, 0 indicates that default port should be used.
        forceConnect - if true and the server adapter is disconnected, an attempt will be made to reconnect.
        Returns:
        repository server handle
        Throws:
        javax.security.auth.login.LoginException - thrown if server fails to authenticate user or general access is denied.
      • clearRepositoryAdapter

        public static void clearRepositoryAdapter​(java.lang.String host,
                                                  int port)
                                           throws java.io.IOException
        Eliminate the specified repository server from the connection cache
        Parameters:
        host - host name or IP address
        port - port (0: use default port)
        Throws:
        java.io.IOException
      • getUserName

        public static java.lang.String getUserName()
        Returns default user login name. Actual user name used by repository should be obtained from RepositoryServerAdapter.getUser
      • handleException

        public static void handleException​(RepositoryAdapter repository,
                                           java.lang.Exception exc,
                                           java.lang.String operation,
                                           boolean mustRetry,
                                           java.awt.Component parent)
        Displays an error dialog appropriate for the given exception. If the exception is a ConnectException or NotConnectedException, a prompt to reconnect to the Ghidra Server is displayed.
        Parameters:
        repository - may be null if the exception is not a RemoteException
        exc - exception that occurred
        operation - operation that was being done when the exception occurred; this string is be used in the message for the error dialog if one should be displayed
        mustRetry - true if the message should state that the user should retry the operation because it may not have succeeded (if the exception was because a RemoteException); there may be cases where the operation succeeded; as a result of the operation, a bad connection to the server was detected (e.g., save a file). Note: this parameter is ignored if the exception is not a ConnectException or NotConnectedException.
        parent - parent of the error dialog
      • handleException

        public static void handleException​(RepositoryAdapter repository,
                                           java.lang.Exception exc,
                                           java.lang.String operation,
                                           java.awt.Component parent)
        Displays an error dialog appropriate for the given exception. If the exception is a ConnectException or NotConnectedException, a prompt to reconnect to the Ghidra Server is displayed. The message states that the operation may have to be retried due to the failed connection.
        Parameters:
        repository - may be null if the exception is not a RemoteException
        exc - exception that occurred
        operation - operation that was being done when the exception occurred; this string is be used in the message for the error dialog if one should be displayed
        parent - parent of the error dialog
      • promptForReconnect

        public static void promptForReconnect​(RepositoryAdapter repository,
                                              java.awt.Component parent)
        Prompt the user to reconnect to the Ghidra Server.
        Parameters:
        repository - repository to connect to
        parent - parent of the dialog
      • checkGhidraServer

        public static void checkGhidraServer​(java.lang.String host,
                                             int port)
                                      throws java.io.IOException
        Connect to a Ghidra Server and verify compatibility. This method can be used to affectively "ping" the Ghidra Server to verify the ability to connect. NOTE: Use of this method when PKI authentication is enabled is not supported.
        Parameters:
        host - server hostname
        port - first Ghidra Server port (0=use default)
        Throws:
        java.io.IOException - thrown if an IO Error occurs (e.g., server not found).
        java.rmi.RemoteException - if server interface is incompatible or another server-side error occurs.
      • changePassword

        public static void changePassword​(java.awt.Component parent,
                                          RepositoryServerHandle handle,
                                          java.lang.String serverInfo)
                                   throws java.io.IOException
        Prompt user and change password on server (not initiated by user).
        Parameters:
        parent - dialog parent
        handle - server handle
        serverInfo - server information
        Throws:
        java.io.IOException
      • isSSHKeyAvailable

        public static boolean isSSHKeyAvailable()