@Override protected Registry getRegistry( String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if(enabled) { return super.getRegistry(registryHost, registryPort, clientSocketFactory, serverSocketFactory); } else { throw new RemoteException(ERR_MSG_NOT_ENABLED); } }
/** * Locate or create the RMI registry for this exporter. * @param registryHost the registry host to use (if this is specified, * no implicit creation of a RMI registry will happen) * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { // Host explicitly specified: only lookup possible. if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]"); } Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory); testRegistry(reg); return reg; } else { return getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } }
/** * Locate or create the RMI registry. * @param registryHost the registry host to use (if this is specified, * no implicit creation of a RMI registry will happen) * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws java.rmi.RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { // Host explicitly specified: only lookup possible. if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]"); } Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory); testRegistry(reg); return reg; } else { return getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } }
@Override protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if(enabled) { return super.getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } else { throw new RemoteException(ERR_MSG_NOT_ENABLED); } }
/** * Locate or create the RMI registry for this exporter. * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { if (this.alwaysCreateRegistry) { logger.info("Creating new RMI registry"); return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); } synchronized (LocateRegistry.class) { try { // Retrieve existing registry. Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); testRegistry(reg); return reg; } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.info("Could not detect RMI registry - creating new one"); // Assume no registry found -> create new one. return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } } } else { return getRegistry(registryPort); } }
/** * Locate or create the RMI registry. * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { if (this.alwaysCreate) { logger.info("Creating new RMI registry"); this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); } synchronized (LocateRegistry.class) { try { // Retrieve existing registry. Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); testRegistry(reg); return reg; } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.info("Could not detect RMI registry - creating new one"); // Assume no registry found -> create new one. this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } } } else { return getRegistry(registryPort); } }
/** * Create a custom socket factory endpoint for a specified host and port. * This should not be used by external classes to create endpoints * for servers in this VM; use getLocalEndpoint instead. */ public TCPEndpoint(String host, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { if (host == null) host = ""; this.host = host; this.port = port; this.csf = csf; this.ssf = ssf; }
public static TCPEndpoint getLocalEndpoint(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { /* * Find mapping for an endpoint key to the list of local unique * endpoints for this client/server socket factory pair (perhaps * null) for the specific port. */ TCPEndpoint ep = null; synchronized (localEndpoints) { TCPEndpoint endpointKey = new TCPEndpoint(null, port, csf, ssf); LinkedList<TCPEndpoint> epList = localEndpoints.get(endpointKey); String localHost = resampleLocalHost(); if (epList == null) { /* * Create new endpoint list. */ ep = new TCPEndpoint(localHost, port, csf, ssf); epList = new LinkedList<TCPEndpoint>(); epList.add(ep); ep.listenPort = port; ep.transport = new TCPTransport(epList); localEndpoints.put(endpointKey, epList); if (TCPTransport.tcpLog.isLoggable(Log.BRIEF)) { TCPTransport.tcpLog.log(Log.BRIEF, "created local endpoint for socket factory " + ssf + " on port " + port); } } else { synchronized (epList) { ep = epList.getLast(); String lastHost = ep.host; int lastPort = ep.port; TCPTransport lastTransport = ep.transport; // assert (localHost == null ^ lastHost != null) if (localHost != null && !localHost.equals(lastHost)) { /* * Hostname has been updated; add updated endpoint * to list. */ if (lastPort != 0) { /* * Remove outdated endpoints only if the * port has already been set on those endpoints. */ epList.clear(); } ep = new TCPEndpoint(localHost, lastPort, csf, ssf); ep.listenPort = port; ep.transport = lastTransport; epList.add(ep); } } } } return ep; }
/** * Construct a new live reference for a server object in the local * address space, to use sockets of the specified type. */ public LiveRef(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { this((new ObjID()), port, csf, ssf); }
public boolean remoteEquals(Object obj) { if (obj != null && obj instanceof LiveRef) { LiveRef ref = (LiveRef) obj; TCPEndpoint thisEp = ((TCPEndpoint) ep); TCPEndpoint refEp = ((TCPEndpoint) ref.ep); RMIClientSocketFactory thisClientFactory = thisEp.getClientSocketFactory(); RMIClientSocketFactory refClientFactory = refEp.getClientSocketFactory(); /** * Fix for 4254103: LiveRef.remoteEquals should not fail * if one of the objects in the comparison has a null * server socket. Comparison should only consider the * following criteria: * * hosts, ports, client socket factories and object IDs. */ if (thisEp.getPort() != refEp.getPort() || !thisEp.getHost().equals(refEp.getHost())) { return false; } if ((thisClientFactory == null) ^ (refClientFactory == null)) { return false; } if ((thisClientFactory != null) && !((thisClientFactory.getClass() == refClientFactory.getClass()) && (thisClientFactory.equals(refClientFactory)))) { return false; } return (id.equals(ref.id)); } else { return false; } }
SystemRegistryImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, ActivationSystem systemStub) throws RemoteException { super(port, csf, ssf); this.systemStub = systemStub; }
SingleEntryRegistry(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, String name, Remote object) throws RemoteException { super(port, csf, ssf); this.name = name; this.object = object; }
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port) throws IOException { RMIClientSocketFactory csf = (RMIClientSocketFactory) env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE); RMIServerSocketFactory ssf = (RMIServerSocketFactory) env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE); return new RMIJRMPServerImpl(port, csf, ssf, env); }
/** * Construct a Unicast server remote reference to be exported * on the specified port. */ public UnicastServerRef2(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { super(new LiveRef(port, csf, ssf)); }
/** * Construct a Unicast server remote reference to be exported * on the specified port. */ public UnicastServerRef2(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, ObjectInputFilter filter) { super(new LiveRef(port, csf, ssf), filter); }
/** * <p>Creates a new {@link RMIServer} object that will be exported * on the given port using the given socket factories.</p> * * @param port the port on which this object and the {@link * RMIConnectionImpl} objects it creates will be exported. Can be * zero, to indicate any available port. * * @param csf the client socket factory for the created RMI * objects. Can be null. * * @param ssf the server socket factory for the created RMI * objects. Can be null. * * @param env the environment map. Can be null. * * @exception IOException if the {@link RMIServer} object * cannot be created. * * @exception IllegalArgumentException if <code>port</code> is * negative. */ public RMIJRMPServerImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, Map<String,?> env) throws IOException { super(env); if (port < 0) throw new IllegalArgumentException("Negative port: " + port); this.port = port; this.csf = csf; this.ssf = ssf; this.env = (env == null) ? Collections.<String, Object>emptyMap() : env; String[] credentialsTypes = (String[]) this.env.get(EnvHelp.CREDENTIAL_TYPES); List<String> types = null; if (credentialsTypes != null) { types = new ArrayList<>(); for (String type : credentialsTypes) { if (type == null) { throw new IllegalArgumentException("A credential type is null."); } ReflectUtil.checkPackageAccess(type); types.add(type); } } exportedWrapper = types != null ? new ExportedWrapper(this, types) : null; }
public Remote exportObject(Remote obj, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { System.out.println("CustomRMIExporter::exportObject():: " + "Remote = " + obj); if (obj.toString().startsWith( "javax.management.remote.rmi.RMIJRMPServerImpl")) rmiServerExported = true; if (obj.toString().startsWith( "javax.management.remote.rmi.RMIConnectionImpl")) rmiConnectionExported = true; return UnicastRemoteObject.exportObject(obj, port, csf, ssf); }
SingleEntryRegistry(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, String name, Remote object) throws RemoteException { super(port, csf, ssf, SingleEntryRegistry::singleRegistryFilter); this.name = name; this.object = object; }
/** * Set the port of the (shared) default endpoint object. * When first created, it contains port 0 because the transport * hasn't tried to listen to get assigned a port, or if listening * failed, a port hasn't been assigned from the server. */ static void setDefaultPort(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { TCPEndpoint endpointKey = new TCPEndpoint(null, 0, csf, ssf); synchronized (localEndpoints) { LinkedList<TCPEndpoint> epList = localEndpoints.get(endpointKey); synchronized (epList) { int size = epList.size(); TCPEndpoint lastEp = epList.getLast(); for (TCPEndpoint ep : epList) { ep.port = port; } if (size > 1) { /* * Remove all but the last element of the list * (which contains the most recent hostname). */ epList.clear(); epList.add(lastEp); } } /* * Allow future exports to use the actual bound port * explicitly (see 6269166). */ TCPEndpoint newEndpointKey = new TCPEndpoint(null, port, csf, ssf); localEndpoints.put(newEndpointKey, epList); if (TCPTransport.tcpLog.isLoggable(Log.BRIEF)) { TCPTransport.tcpLog.log(Log.BRIEF, "default port for server socket factory " + ssf + " and client socket factory " + csf + " set to " + port); } } }
SystemRegistryImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, ActivationSystem systemStub) throws RemoteException { super(port, csf, ssf); assert systemStub != null; synchronized (this) { this.systemStub = systemStub; notifyAll(); } }
/** * Construct a new RegistryImpl on the specified port with the * given custom socket factory pair. */ public RegistryImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { this(port, csf, ssf, RegistryImpl::registryFilter); }
/** * ObjectInputFilter to filter Registry input objects. * The list of acceptable classes is limited to classes normally * stored in a registry. * * @param filterInfo access to the class, array length, etc. * @return {@link ObjectInputFilter.Status#ALLOWED} if allowed, * {@link ObjectInputFilter.Status#REJECTED} if rejected, * otherwise {@link ObjectInputFilter.Status#UNDECIDED} */ private static ObjectInputFilter.Status registryFilter(ObjectInputFilter.FilterInfo filterInfo) { if (registryFilter != null) { ObjectInputFilter.Status status = registryFilter.checkInput(filterInfo); if (status != ObjectInputFilter.Status.UNDECIDED) { // The Registry filter can override the built-in white-list return status; } } if (filterInfo.depth() > REGISTRY_MAX_DEPTH) { return ObjectInputFilter.Status.REJECTED; } Class<?> clazz = filterInfo.serialClass(); if (clazz != null) { if (clazz.isArray()) { // Arrays are REJECTED only if they exceed the limit return (filterInfo.arrayLength() >= 0 && filterInfo.arrayLength() > REGISTRY_MAX_ARRAY_SIZE) ? ObjectInputFilter.Status.REJECTED : ObjectInputFilter.Status.UNDECIDED; } if (String.class == clazz || java.lang.Number.class.isAssignableFrom(clazz) || Remote.class.isAssignableFrom(clazz) || java.lang.reflect.Proxy.class.isAssignableFrom(clazz) || UnicastRef.class.isAssignableFrom(clazz) || RMIClientSocketFactory.class.isAssignableFrom(clazz) || RMIServerSocketFactory.class.isAssignableFrom(clazz) || java.rmi.activation.ActivationID.class.isAssignableFrom(clazz) || java.rmi.server.UID.class.isAssignableFrom(clazz)) { return ObjectInputFilter.Status.ALLOWED; } else { return ObjectInputFilter.Status.REJECTED; } } return ObjectInputFilter.Status.UNDECIDED; }