Search in sources :

Example 1 with UnicastRef2

use of sun.rmi.server.UnicastRef2 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 2 with UnicastRef2

use of sun.rmi.server.UnicastRef2 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)

Example 3 with UnicastRef2

use of sun.rmi.server.UnicastRef2 in project jdk8u_jdk by JetBrains.

the class LocateRegistry method getRegistry.

/**
     * Returns a locally created remote reference to the remote object
     * <code>Registry</code> on the specified <code>host</code> and
     * <code>port</code>.  Communication with this remote registry will
     * use the supplied <code>RMIClientSocketFactory</code> <code>csf</code>
     * to create <code>Socket</code> connections to the registry on the
     * remote <code>host</code> and <code>port</code>.
     *
     * @param host host for the remote registry
     * @param port port on which the registry accepts requests
     * @param csf  client-side <code>Socket</code> factory used to
     *      make connections to the registry.  If <code>csf</code>
     *      is null, then the default client-side <code>Socket</code>
     *      factory will be used in the registry stub.
     * @return reference (a stub) to the remote registry
     * @exception RemoteException if the reference could not be created
     * @since 1.2
     */
public static Registry getRegistry(String host, int port, RMIClientSocketFactory csf) throws RemoteException {
    Registry registry = null;
    if (port <= 0)
        port = Registry.REGISTRY_PORT;
    if (host == null || host.length() == 0) {
        // that the RegistryImpl's checkAccess will not fail.
        try {
            host = java.net.InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            // If that failed, at least try "" (localhost) anyway...
            host = "";
        }
    }
    /*
         * Create a proxy for the registry with the given host, port, and
         * client socket factory.  If the supplied client socket factory is
         * null, then the ref type is a UnicastRef, otherwise the ref type
         * is a UnicastRef2.  If the property
         * java.rmi.server.ignoreStubClasses is true, then the proxy
         * returned is an instance of a dynamic proxy class that implements
         * the Registry interface; otherwise the proxy returned is an
         * instance of the pregenerated stub class for RegistryImpl.
         **/
    LiveRef liveRef = new LiveRef(new ObjID(ObjID.REGISTRY_ID), new TCPEndpoint(host, port, csf, null), false);
    RemoteRef ref = (csf == null) ? new UnicastRef(liveRef) : new UnicastRef2(liveRef);
    return (Registry) Util.createProxy(RegistryImpl.class, ref, false);
}
Also used : RegistryImpl(sun.rmi.registry.RegistryImpl) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) LiveRef(sun.rmi.transport.LiveRef) ObjID(java.rmi.server.ObjID) RemoteRef(java.rmi.server.RemoteRef) UnicastRef2(sun.rmi.server.UnicastRef2) UnicastRef(sun.rmi.server.UnicastRef) RemoteException(java.rmi.RemoteException)

Aggregations

UnicastRef2 (sun.rmi.server.UnicastRef2)3 LiveRef (sun.rmi.transport.LiveRef)3 RemoteRef (java.rmi.server.RemoteRef)2 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Remote (java.rmi.Remote)1 RemoteException (java.rmi.RemoteException)1 ObjID (java.rmi.server.ObjID)1 RMIClientSocketFactory (java.rmi.server.RMIClientSocketFactory)1 RemoteObject (java.rmi.server.RemoteObject)1 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)1 RegistryImpl (sun.rmi.registry.RegistryImpl)1 UnicastRef (sun.rmi.server.UnicastRef)1 TCPEndpoint (sun.rmi.transport.tcp.TCPEndpoint)1