Package ghidra.framework.client

# Class ClientUtil

java.lang.Object
ghidra.framework.client.ClientUtil

public class ClientUtil extends Object
`ClientUtil` allows a user to connect to a Repository Server and obtain its handle.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `changePassword(Component parent, RepositoryServerHandle handle, String serverInfo)`
  Prompt user and change password on server (not initiated by user).
  `static void`
  `checkGhidraServer(String host, int port, TaskMonitor monitor)`
  Connect to a Ghidra Server and verify compatibility.
  `static void`
  `clearRepositoryAdapter(String host, int port)`
  Eliminate the specified repository server from the connection cache
  `static ClientAuthenticator`
  `getClientAuthenticator()`
  Get the currently installed client authenticator.
  `static RepositoryServerAdapter`
  `getRepositoryServer(String host, int port)`
  Connect to a Repository Server and obtain a handle to it.
  `static RepositoryServerAdapter`
  `getRepositoryServer(String host, int port, boolean forceConnect)`
  Connect to a Repository Server and obtain a handle to it.
  `static String`
  `getUserName()`
  Returns default user login name.
  `static void`
  `handleException(RepositoryAdapter repository, Exception exc, String operation, boolean mustRetry, Component parent)`
  Displays an error dialog appropriate for the given exception.
  `static void`
  `handleException(RepositoryAdapter repository, Exception exc, String operation, Component parent)`
  Displays an error dialog appropriate for the given exception.
  `static boolean`
  `isConnected(String host, int port)`
  Determine if a connected `RepositoryServerAdapter` already exists for the specified server.
  `static boolean`
  `isSSHKeyAvailable()`
  `static void`
  `promptForReconnect(RepositoryAdapter repository, Component parent)`
  Prompt the user to reconnect to the Ghidra Server.
  `static void`
  `setClientAuthenticator(ClientAuthenticator authenticator)`
  Set client authenticator

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### setClientAuthenticator

    public static void setClientAuthenticator(ClientAuthenticator authenticator)
    Set client authenticator
    Parameters:
      `authenticator` - client authenticator instance

  - ### 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(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

  - ### getRepositoryServer

    public static RepositoryServerAdapter getRepositoryServer(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

  - ### isConnected

    public static boolean isConnected(String host, int port)
    Determine if a connected `RepositoryServerAdapter` already exists for the specified server.
    Parameters:
      `host` - server name or address
      `port` - server port, 0 indicates that default port applies.
    Returns:
      true if connection already exists, else false

  - ### clearRepositoryAdapter

    public static void clearRepositoryAdapter(String host, int port)
    Eliminate the specified repository server from the connection cache
    Parameters:
      `host` - host name or IP address
      `port` - port (0: use default port)

  - ### getUserName

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

  - ### handleException

    public static void handleException(RepositoryAdapter repository, Exception exc, String operation, boolean mustRetry, 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, Exception exc, String operation, 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, 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(String host, int port, TaskMonitor monitor) throws IOException, CancelledException
    Connect to a Ghidra Server and verify compatibility. This method can be used to effectively "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)
      `monitor` - cancellable monitor
    Throws:
      `IOException` - thrown if an IO Error occurs (e.g., server not found).
      `RemoteException` - if server interface is incompatible or another server-side error occurs.
      `CancelledException` - if connection attempt was cancelled

  - ### changePassword

    public static void changePassword(Component parent, RepositoryServerHandle handle, String serverInfo) throws IOException
    Prompt user and change password on server (not initiated by user).
    Parameters:
      `parent` - dialog parent
      `handle` - server handle
      `serverInfo` - server information
    Throws:
      `IOException` - if error occurs while updating password

  - ### isSSHKeyAvailable

    public static boolean isSSHKeyAvailable()