Search in sources :

Example 1 with LiveRef

use of sun.rmi.transport.LiveRef in project jdk8u_jdk by JetBrains.

the class FilterUSRTest method UnicastServerRef.

/*
     * Test exporting an object with a serialFilter using UnicastServerRef.exportObject().
     * Send some objects and check the number of calls to the serialFilter.
     */
@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())) {
            // normal expected exception
            return;
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
Also used : LiveRef(sun.rmi.transport.LiveRef) UnmarshalException(java.rmi.UnmarshalException) UnicastServerRef(sun.rmi.server.UnicastServerRef) RemoteException(java.rmi.RemoteException) UnmarshalException(java.rmi.UnmarshalException) RemoteException(java.rmi.RemoteException) InvalidClassException(java.io.InvalidClassException) Test(org.testng.annotations.Test)

Example 2 with LiveRef

use of sun.rmi.transport.LiveRef in project jdk8u_jdk by JetBrains.

the class RMIConnector method checkStub.

//--------------------------------------------------------------------
// Private stuff - Check if stub can be trusted.
//--------------------------------------------------------------------
private static void checkStub(Remote stub, Class<?> stubClass) {
    //
    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!");
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RemoteObject(java.rmi.server.RemoteObject) LiveRef(sun.rmi.transport.LiveRef) RemoteRef(java.rmi.server.RemoteRef) Remote(java.rmi.Remote) UnicastRef2(sun.rmi.server.UnicastRef2) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 3 with LiveRef

use of sun.rmi.transport.LiveRef in project jdk8u_jdk by JetBrains.

the class TestLibrary method getRegistryPort.

/**
     * 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;
}
Also used : RegistryImpl(sun.rmi.registry.RegistryImpl) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) LiveRef(sun.rmi.transport.LiveRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) RemoteRef(java.rmi.server.RemoteRef) UnicastServerRef(sun.rmi.server.UnicastServerRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) NoSuchObjectException(java.rmi.NoSuchObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 4 with LiveRef

use of sun.rmi.transport.LiveRef in project jdk8u_jdk by JetBrains.

the class InterfaceHash method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 4472769");
    System.err.println("\n=== verifying that J2SE registry's skeleton uses" + "\ncorrect interface hash and operation numbers:");
    Registry testImpl = LocateRegistry.createRegistry(PORT);
    System.err.println("created test registry on port " + PORT);
    RemoteRef ref = new UnicastRef(new LiveRef(new ObjID(ObjID.REGISTRY_ID), new TCPEndpoint("", PORT), false));
    Registry referenceStub = new ReferenceRegistryStub(ref);
    System.err.println("created reference registry stub: " + referenceStub);
    referenceStub.bind(NAME, referenceStub);
    System.err.println("bound name \"" + NAME + "\" in registry");
    String[] list = referenceStub.list();
    System.err.println("list of registry contents: " + Arrays.asList(list));
    if (list.length != 1 || !list[0].equals(NAME)) {
        throw new RuntimeException("TEST FAILED: unexpected list contents");
    }
    Registry result = (Registry) referenceStub.lookup(NAME);
    System.err.println("lookup of name \"" + NAME + "\" returned: " + result);
    if (!result.equals(referenceStub)) {
        throw new RuntimeException("TEST FAILED: unexpected lookup result");
    }
    referenceStub.rebind(NAME, referenceStub);
    referenceStub.unbind(NAME);
    System.err.println("unbound name \"" + NAME + "\"");
    list = referenceStub.list();
    System.err.println("list of registry contents: " + Arrays.asList(list));
    if (list.length != 0) {
        throw new RuntimeException("TEST FAILED: list not empty");
    }
    System.err.println("\n=== verifying that J2SE registry's stub uses" + "correct interface hash:");
    class FakeRemoteRef implements RemoteRef {

        long hash;

        int opnum;

        public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) {
            this.hash = hash;
            this.opnum = opnum;
            throw new UnsupportedOperationException();
        }

        public void invoke(RemoteCall call) {
        }

        public void done(RemoteCall call) {
        }

        public Object invoke(Remote obj, Method method, Object[] args, long hash) {
            throw new UnsupportedOperationException();
        }

        public String getRefClass(java.io.ObjectOutput out) {
            return "FakeRemoteRef";
        }

        public int remoteHashCode() {
            return 1013;
        }

        public boolean remoteEquals(RemoteRef obj) {
            return false;
        }

        public String remoteToString() {
            return "FakeRemoteRef";
        }

        public void writeExternal(java.io.ObjectOutput out) {
        }

        public void readExternal(java.io.ObjectInput in) {
        }
    }
    FakeRemoteRef f = new FakeRemoteRef();
    Registry testRegistry = LocateRegistry.getRegistry(PORT);
    System.err.println("created original test registry stub: " + testRegistry);
    Class stubClass = testRegistry.getClass();
    System.err.println("test registry stub class: " + stubClass);
    Constructor cons = stubClass.getConstructor(new Class[] { RemoteRef.class });
    Registry testStub = (Registry) cons.newInstance(new Object[] { f });
    System.err.println("created new instrumented test registry stub: " + testStub);
    System.err.println("invoking bind:");
    try {
        testStub.bind(NAME, referenceStub);
    } catch (UnsupportedOperationException e) {
    }
    System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
    if (f.hash != 4905912898345647071L) {
        throw new RuntimeException("TEST FAILED: wrong interface hash");
    } else if (f.opnum != 0) {
        throw new RuntimeException("TEST FAILED: wrong operation number");
    }
    System.err.println("invoking list:");
    try {
        testStub.list();
    } catch (UnsupportedOperationException e) {
    }
    System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
    if (f.hash != 4905912898345647071L) {
        throw new RuntimeException("TEST FAILED: wrong interface hash");
    } else if (f.opnum != 1) {
        throw new RuntimeException("TEST FAILED: wrong operation number");
    }
    System.err.println("invoking lookup:");
    try {
        testStub.lookup(NAME);
    } catch (UnsupportedOperationException e) {
    }
    System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
    if (f.hash != 4905912898345647071L) {
        throw new RuntimeException("TEST FAILED: wrong interface hash");
    } else if (f.opnum != 2) {
        throw new RuntimeException("TEST FAILED: wrong operation number");
    }
    System.err.println("invoking rebind:");
    try {
        testStub.rebind(NAME, referenceStub);
    } catch (UnsupportedOperationException e) {
    }
    System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
    if (f.hash != 4905912898345647071L) {
        throw new RuntimeException("TEST FAILED: wrong interface hash");
    } else if (f.opnum != 3) {
        throw new RuntimeException("TEST FAILED: wrong operation number");
    }
    System.err.println("invoking unbind:");
    try {
        testStub.unbind(NAME);
    } catch (UnsupportedOperationException e) {
    }
    System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
    if (f.hash != 4905912898345647071L) {
        throw new RuntimeException("TEST FAILED: wrong interface hash");
    } else if (f.opnum != 4) {
        throw new RuntimeException("TEST FAILED: wrong operation number");
    }
    System.err.println("TEST PASSED");
}
Also used : Constructor(java.lang.reflect.Constructor) RemoteRef(java.rmi.server.RemoteRef) Remote(java.rmi.Remote) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) Method(java.lang.reflect.Method) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) LiveRef(sun.rmi.transport.LiveRef) RemoteObject(java.rmi.server.RemoteObject) ObjID(java.rmi.server.ObjID) RemoteObject(java.rmi.server.RemoteObject) UnicastRef(sun.rmi.server.UnicastRef) RemoteCall(java.rmi.server.RemoteCall)

Example 5 with LiveRef

use of sun.rmi.transport.LiveRef in project jdk8u_jdk by JetBrains.

the class ProxyClient method checkStub.

private static void checkStub(Remote stub, Class<? extends Remote> stubClass) {
    //
    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!");
    }
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) LiveRef(sun.rmi.transport.LiveRef) UnicastRef2(sun.rmi.server.UnicastRef2) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory)

Aggregations

LiveRef (sun.rmi.transport.LiveRef)7 RemoteRef (java.rmi.server.RemoteRef)4 TCPEndpoint (sun.rmi.transport.tcp.TCPEndpoint)4 RemoteException (java.rmi.RemoteException)3 ObjID (java.rmi.server.ObjID)3 UnicastRef (sun.rmi.server.UnicastRef)3 UnicastRef2 (sun.rmi.server.UnicastRef2)3 Remote (java.rmi.Remote)2 Registry (java.rmi.registry.Registry)2 RemoteObject (java.rmi.server.RemoteObject)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)2 RegistryImpl (sun.rmi.registry.RegistryImpl)2 UnicastServerRef (sun.rmi.server.UnicastServerRef)2 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1 Constructor (java.lang.reflect.Constructor)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1