sun.rmi.transport.LiveRef Java Examples

The following examples show how to use sun.rmi.transport.LiveRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterUSRTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);

        Echo client = (Echo) ref.exportObject(impl, null, false);

        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 &&
                UnmarshalException.class.equals(rex.getCause().getClass()) &&
                InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            return; // normal expected exception
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
 
Example #2
Source File: FilterUSRTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);

        Echo client = (Echo) ref.exportObject(impl, null, false);

        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 &&
                UnmarshalException.class.equals(rex.getCause().getClass()) &&
                InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            return; // normal expected exception
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
 
Example #3
Source File: TestLibrary.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the port number the RMI {@link Registry} is running on.
 *
 * @param registry the registry to find the port of.
 * @return the port number the registry is using.
 * @throws RuntimeException if there was a problem getting the port number.
 */
public static int getRegistryPort(Registry registry) {
    int port = -1;

    try {
        RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
        LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }

    return port;
}
 
Example #4
Source File: JRMPClient.java    From ysoserial with MIT License 6 votes vote down vote up
public Registry getObject ( final String command ) throws Exception {

        String host;
        int port;
        int sep = command.indexOf(':');
        if ( sep < 0 ) {
            port = new Random().nextInt(65535);
            host = command;
        }
        else {
            host = command.substring(0, sep);
            port = Integer.valueOf(command.substring(sep + 1));
        }
        ObjID id = new ObjID(new Random().nextInt()); // RMI registry
        TCPEndpoint te = new TCPEndpoint(host, port);
        UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
        RemoteObjectInvocationHandler obj = new RemoteObjectInvocationHandler(ref);
        Registry proxy = (Registry) Proxy.newProxyInstance(JRMPClient.class.getClassLoader(), new Class[] {
            Registry.class
        }, obj);
        return proxy;
    }
 
Example #5
Source File: TestLibrary.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the port number the RMI {@link Registry} is running on.
 *
 * @param registry the registry to find the port of.
 * @return the port number the registry is using.
 * @throws RuntimeException if there was a problem getting the port number.
 */
public static int getRegistryPort(Registry registry) {
    int port = -1;

    try {
        RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
        LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }

    return port;
}
 
Example #6
Source File: TestLibrary.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the port number the RMI {@link Registry} is running on.
 *
 * @param registry the registry to find the port of.
 * @return the port number the registry is using.
 * @throws RuntimeException if there was a problem getting the port number.
 */
public static int getRegistryPort(Registry registry) {
    int port = -1;

    try {
        RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
        LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }

    return port;
}
 
Example #7
Source File: TestLibrary.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the port number the RMI {@link Registry} is running on.
 *
 * @param registry the registry to find the port of.
 * @return the port number the registry is using.
 * @throws RuntimeException if there was a problem getting the port number.
 */
public static int getRegistryPort(Registry registry) {
    int port = -1;

    try {
        RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
        LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }

    return port;
}
 
Example #8
Source File: JDKUtil.java    From learnjavabug with MIT License 5 votes vote down vote up
private static Object makeRegistryImpl ( String codebase, String clazz ) throws IllegalArgumentException, Exception {
    Class<?> regcl = Class.forName("sun.management.jmxremote.SingleEntryRegistry");
    Object reg = Reflections.createWithoutConstructor(regcl);
    Reflections.setFieldValue(reg, "name", "exp");

    TCPEndpoint te = new TCPEndpoint("127.0.0.1", 1337);
    LiveRef liveRef = new LiveRef(new ObjID(), te, true);
    UnicastRef value = new UnicastRef(liveRef);
    Reflections.setFieldValue(reg, "ref", value);
    Reflections.setFieldValue(reg, "object", makeReference(codebase, clazz));
    return reg;
}
 
Example #9
Source File: ProxyClient.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #10
Source File: UnicastServerRef2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: Activation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new SameHostOnlyServerRef(lref,
            "ActivationSystem.nonLocalAccess");
    ref = uref;
    uref.exportObject(this, null);
}
 
Example #12
Source File: UnicastServerRef2.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #13
Source File: UnicastServerRef2.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source File: ProxyClient.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #15
Source File: UnicastServerRef2.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #16
Source File: Activation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new Activator on a specified port.
 */
ActivatorImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref =
        new LiveRef(new ObjID(ObjID.ACTIVATOR_ID), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null, false);
}
 
Example #17
Source File: UnicastServerRef2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #18
Source File: ProxyClient.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #19
Source File: Activation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new Activator on a specified port.
 */
ActivatorImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref =
        new LiveRef(new ObjID(ObjID.ACTIVATOR_ID), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null, false);
}
 
Example #20
Source File: ProxyClient.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #21
Source File: Activation.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new SameHostOnlyServerRef(lref,
            "ActivationSystem.nonLocalAccess");
    ref = uref;
    uref.exportObject(this, null);
}
 
Example #22
Source File: Activation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new Activator on a specified port.
 */
ActivatorImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref =
        new LiveRef(new ObjID(ObjID.ACTIVATOR_ID), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null, false);
}
 
Example #23
Source File: ProxyClient.java    From jvmtop with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #24
Source File: Activation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null);
}
 
Example #25
Source File: UnicastServerRef2.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #26
Source File: JDKUtil.java    From marshalsec with MIT License 5 votes vote down vote up
private static Object makeRegistryImpl ( String codebase, String clazz ) throws IllegalArgumentException, Exception {
    Class<?> regcl = Class.forName("sun.management.jmxremote.SingleEntryRegistry");
    Object reg = Reflections.createWithoutConstructor(regcl);
    Reflections.setFieldValue(reg, "name", "exp");

    TCPEndpoint te = new TCPEndpoint("127.0.0.1", 1337);
    LiveRef liveRef = new LiveRef(new ObjID(), te, true);
    UnicastRef value = new UnicastRef(liveRef);
    Reflections.setFieldValue(reg, "ref", value);
    Reflections.setFieldValue(reg, "object", makeReference(codebase, clazz));
    return reg;
}
 
Example #27
Source File: ProxyClient.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #28
Source File: ProxyClient.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
                              Class<? extends Remote> stubClass) {
    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class) {
                throw new SecurityException(
                    "Expecting a dynamic proxy instance with a " +
                    RemoteObjectInvocationHandler.class.getName() +
                    " invocation handler!");
            } else {
                stub = (Remote) handler;
            }
        }
    }
    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class) {
        throw new SecurityException(
            "Expecting a " + UnicastRef2.class.getName() +
            " remote reference in stub!");
    }
    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
        throw new SecurityException(
            "Expecting a " + SslRMIClientSocketFactory.class.getName() +
            " RMI client socket factory in stub!");
    }
}
 
Example #29
Source File: UnicastServerRef2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #30
Source File: ActivatableServerRef.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public ActivatableServerRef(ActivationID id, int port,
                            RMIClientSocketFactory csf,
                            RMIServerSocketFactory ssf)
{
    super(new LiveRef(port, csf, ssf));
    this.id = id;
}