Package eu.tneitzel.rmg.networking
Class LoopbackSocketFactory
- java.lang.Object
-
- java.rmi.server.RMISocketFactory
-
- eu.tneitzel.rmg.networking.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)
-
-
Constructor Summary
Constructors Constructor Description LoopbackSocketFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServerSocketcreateServerSocket(int port)SocketcreateSocket(String host, int port)Overwrites the default implementation of createSocket.-
Methods inherited from class java.rmi.server.RMISocketFactory
getDefaultSocketFactory, getFailureHandler, getSocketFactory, setFailureHandler, setSocketFactory
-
-
-
-
Method Detail
-
createServerSocket
public ServerSocket createServerSocket(int port) throws IOException
- Specified by:
createServerSocketin interfaceRMIServerSocketFactory- Specified by:
createServerSocketin classRMISocketFactory- Throws:
IOException
-
createSocket
public Socket createSocket(String host, int port) throws IOException
Overwrites the default implementation of createSocket. Checks whether host matches the expected value and changes the value if required. After the host check was done, the default socket factory is used to create the real socket.- Specified by:
createSocketin interfaceRMIClientSocketFactory- Specified by:
createSocketin classRMISocketFactory- Throws:
IOException
-
-