8165806: UnicastServerRef support to export an object with a filter
Reviewed-by: dfuchs
This commit is contained in:
parent
9aa8b6728a
commit
6a5d225ba3
jdk/src/java.rmi/share/classes/sun/rmi/server
@ -27,6 +27,8 @@ package sun.rmi.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectInputFilter;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -62,6 +64,10 @@ import sun.rmi.transport.tcp.TCPTransport;
|
||||
* UnicastServerRef implements the remote reference layer server-side
|
||||
* behavior for remote objects exported with the "UnicastRef" reference
|
||||
* type.
|
||||
* If an {@link ObjectInputFilter ObjectInputFilter} is supplied it is
|
||||
* invoked during deserialization to filter the arguments,
|
||||
* otherwise the default filter of {@link ObjectInputStream ObjectInputStream}
|
||||
* applies.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Roger Riggs
|
||||
@ -103,6 +109,9 @@ public class UnicastServerRef extends UnicastRef
|
||||
*/
|
||||
private transient Skeleton skel;
|
||||
|
||||
// The ObjectInputFilter for checking the invocation arguments
|
||||
private final transient ObjectInputFilter filter;
|
||||
|
||||
/** maps method hash to Method object for each remote method */
|
||||
private transient Map<Long,Method> hashToMethod_Map = null;
|
||||
|
||||
@ -121,16 +130,29 @@ public class UnicastServerRef extends UnicastRef
|
||||
|
||||
/**
|
||||
* Create a new (empty) Unicast server remote reference.
|
||||
* The filter is null to defer to the default ObjectInputStream filter, if any.
|
||||
*/
|
||||
public UnicastServerRef() {
|
||||
this.filter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Unicast server remote reference for a specified
|
||||
* liveRef.
|
||||
* The filter is null to defer to the default ObjectInputStream filter, if any.
|
||||
*/
|
||||
public UnicastServerRef(LiveRef ref) {
|
||||
super(ref);
|
||||
this.filter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Unicast server remote reference for a specified
|
||||
* liveRef and filter.
|
||||
*/
|
||||
public UnicastServerRef(LiveRef ref, ObjectInputFilter filter) {
|
||||
super(ref);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +161,7 @@ public class UnicastServerRef extends UnicastRef
|
||||
*/
|
||||
public UnicastServerRef(int port) {
|
||||
super(new LiveRef(port));
|
||||
this.filter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -363,9 +386,23 @@ public class UnicastServerRef extends UnicastRef
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter for invocation arguments, if a filter has been set.
|
||||
* Called by dispatch before the arguments are read.
|
||||
*/
|
||||
protected void unmarshalCustomCallData(ObjectInput in)
|
||||
throws IOException, ClassNotFoundException
|
||||
{}
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (filter != null &&
|
||||
in instanceof ObjectInputStream) {
|
||||
// Set the filter on the stream
|
||||
ObjectInputStream ois = (ObjectInputStream) in;
|
||||
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
|
||||
ois.setObjectInputFilter(filter);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle server-side dispatch using the RMI 1.1 stub/skeleton
|
||||
|
@ -25,12 +25,13 @@
|
||||
|
||||
package sun.rmi.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputFilter;
|
||||
import java.io.ObjectOutput;
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.*;
|
||||
import sun.rmi.transport.*;
|
||||
import sun.rmi.transport.tcp.*;
|
||||
import java.rmi.server.RMIClientSocketFactory;
|
||||
import java.rmi.server.RMIServerSocketFactory;
|
||||
import java.rmi.server.RemoteRef;
|
||||
|
||||
import sun.rmi.transport.LiveRef;
|
||||
|
||||
/**
|
||||
* Server-side ref for a remote impl that uses a custom socket factory.
|
||||
@ -58,6 +59,16 @@ public class UnicastServerRef2 extends UnicastServerRef
|
||||
super(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Unicast server remote reference for a specified
|
||||
* liveRef and filter.
|
||||
*/
|
||||
public UnicastServerRef2(LiveRef ref,
|
||||
ObjectInputFilter filter)
|
||||
{
|
||||
super(ref, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Unicast server remote reference to be exported
|
||||
* on the specified port.
|
||||
@ -69,6 +80,18 @@ public class UnicastServerRef2 extends UnicastServerRef
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the ref type to be serialized
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user