Class LoopbackSocketFactory

  • All Implemented Interfaces:
    RMIClientSocketFactory, RMIServerSocketFactory

    public class LoopbackSocketFactory
    extends RMISocketFactory
    Remote objects bound to an RMI registry are usually pointing to remote endpoints on the same host. In order to protect from unauthorized access, some developers suggest setting these references to localhost or 127.0.0.1 explicitly. This will indeed cause hiccups in most RMI clients, as they try to call to 127.0.0.1 after fetching a remote object. However, when the TCP ports of the corresponding remote objects are open, it is still possible to communicate with them. The LoopbackSocketFactory class extends the default RMISocketFactory and can be set as a replacement. The class uses remote-method-guessers global option access to obtain actual target of the RMI communication (usually the registry host). All other RMI connections are then expected to target the same host. This is implemented by overwriting the createSocket function. If the specified host value does not match the expected value, it is replaced by the expected value and the connection is therefore redirected. During a redirect, the class prints a warning to the user to inform about the redirection. If redirection is a desired behavior, the user can use the --follow option with rmg, which sets the followRedirect attribute to true. In these cases, a warning is still printed, but the connection goes to the specified target.
    Author:
    Tobias Neitzel (@qtc_de)