net.jini.security.proxytrust
Class ProxyTrustInvocationHandler

java.lang.Object
  extended by net.jini.security.proxytrust.ProxyTrustInvocationHandler
All Implemented Interfaces:
Serializable, InvocationHandler, TrustEquivalence

public final class ProxyTrustInvocationHandler
extends Object
implements InvocationHandler, TrustEquivalence, Serializable

Invocation handler for remote objects, supporting proxy trust verification by clients using ProxyTrustVerifier. This invocation handler contains both an underlying main proxy and a bootstrap proxy; the main proxy is not expected to be considered trusted directly by clients, but the bootstrap proxy is. The main proxy must be an instance of both RemoteMethodControl and TrustEquivalence, and the bootstrap proxy must be an instance of ProxyTrust, RemoteMethodControl, and TrustEquivalence. This invocation handler handles most method invocations by delegating to the main proxy. The bootstrap proxy is produced by the iterator returned by the getProxyTrustIterator method, as required by ProxyTrustVerifier.

Since:
2.0
Author:
Sun Microsystems, Inc.
See Also:
Serialized Form

Field Summary
private  ProxyTrust boot
          The bootstrap proxy.
private static Class[] consArgs
           
private  RemoteMethodControl main
          The main proxy.
private static long serialVersionUID
           
 
Constructor Summary
ProxyTrustInvocationHandler(RemoteMethodControl main, ProxyTrust boot)
          Creates an instance with the specified main proxy and bootstrap proxy.
 
Method Summary
 boolean checkTrustEquivalence(Object obj)
          Returns true if the argument is an instance of this class, and calling the checkTrustEquivalence method on the main proxy of this invocation handler, passing the main proxy of the argument, returns true, and calling the checkTrustEquivalence method on the bootstrap proxy of this invocation handler, passing the bootstrap proxy of the argument, returns true, and returns false otherwise.
 boolean equals(Object obj)
          Returns true if the argument is an instance of this class with the same main proxy and the same bootstrap proxy, and false otherwise.
protected  ProxyTrustIterator getProxyTrustIterator()
          Returns an iterator that produces the bootstrap proxy as the only element of the iteration.
 int hashCode()
          Returns a hash code value for this object.
 Object invoke(Object proxy, Method method, Object[] args)
          Executes the specified method with the specified arguments on the specified proxy, and returns the return value, if any.
private  Object invoke0(Method m, Object[] args)
          Reflectively invoke the method on the main proxy, unless the method's declaring class is not public but the main proxy's class is public, in which case invoke the corresponding method from the main proxy's class instead.
private  String proxyToString(Object proxy)
          Returns a string representation for a proxy that uses this invocation handler.
private  void readObject(ObjectInputStream s)
          Verifies that the main proxy is an instance of TrustEquivalence, and that the bootstrap proxy is an instance of both RemoteMethodControl and TrustEquivalence.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

consArgs

private static final Class[] consArgs

main

private final RemoteMethodControl main
The main proxy.


boot

private final ProxyTrust boot
The bootstrap proxy.

Constructor Detail

ProxyTrustInvocationHandler

public ProxyTrustInvocationHandler(RemoteMethodControl main,
                                   ProxyTrust boot)
Creates an instance with the specified main proxy and bootstrap proxy.

Parameters:
main - the main proxy
boot - the bootstrap proxy
Throws:
NullPointerException - if any argument is null
IllegalArgumentException - if the main proxy is not an instance of TrustEquivalence, or the bootstrap proxy is not an instance of RemoteMethodControl or TrustEquivalence
Method Detail

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Executes the specified method with the specified arguments on the specified proxy, and returns the return value, if any.

If the specified method is Object.equals, returns true if the argument (args[0]) is an instance of a dynamic proxy class (that is, a class generated by Proxy) that implements the same interfaces as the specified proxy and this invocation handler is equal to the invocation handler of that argument, and returns false otherwise.

If the specified method is Object.toString, returns a string representation of the specified proxy object.

If the specified method is Object.hashCode, returns a hash code for the specified proxy object.

If the specified method is RemoteMethodControl.setConstraints, returns a new proxy (an instance of the same class as the specified proxy) containing an instance of this class with a new main proxy and the same bootstrap proxy from this handler. The new main proxy is obtained by delegating to the existing main proxy of this handler (as described below). An exception is thrown if the specified proxy is not an instance of a dynamic proxy class containing this invocation handler.

If the specified method is TrustEquivalence.checkTrustEquivalence, returns true if the argument (args[0]) is an instance of a dynamic proxy class that implements the same interfaces as the specified proxy and calling the checkTrustEquivalence method of this invocation handler with the invocation handler of that argument returns true, and returns false otherwise.

For all other methods, returns the object obtained by delegating to the main proxy: the specified method is reflectively invoked on the main proxy with the specified arguments, unless the method's declaring class is not public but the main proxy is an instance of that declaring class and the main proxy's class is public, in which case the corresponding method of the main proxy's class is reflectively invoked instead.

The semantics of this method are unspecified if the arguments could not have been produced by an instance of some valid dynamic proxy class containing this invocation handler.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - the proxy object
method - the method being invoked
args - the arguments to the specified method
Returns:
the value returned by executing the specified method on the specified proxy with the specified arguments, or null if the method has void return type
Throws:
Throwable - the exception thrown by executing the specified method
IllegalArgumentException - if the declaring class of the specified method is not public and either the main proxy is not an instance of that declaring class or the main proxy's class is not public

invoke0

private Object invoke0(Method m,
                       Object[] args)
                throws Throwable
Reflectively invoke the method on the main proxy, unless the method's declaring class is not public but the main proxy's class is public, in which case invoke the corresponding method from the main proxy's class instead.

Throws:
Throwable

checkTrustEquivalence

public boolean checkTrustEquivalence(Object obj)
Returns true if the argument is an instance of this class, and calling the checkTrustEquivalence method on the main proxy of this invocation handler, passing the main proxy of the argument, returns true, and calling the checkTrustEquivalence method on the bootstrap proxy of this invocation handler, passing the bootstrap proxy of the argument, returns true, and returns false otherwise.

Specified by:
checkTrustEquivalence in interface TrustEquivalence
Parameters:
obj - object to check that is not yet known to be trusted
Returns:
true if the specified object (that is not yet known to be trusted) is equivalent in trust, content, and function to this known trusted object, and returns false otherwise

equals

public boolean equals(Object obj)
Returns true if the argument is an instance of this class with the same main proxy and the same bootstrap proxy, and false otherwise.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object

proxyToString

private String proxyToString(Object proxy)
Returns a string representation for a proxy that uses this invocation handler.


getProxyTrustIterator

protected ProxyTrustIterator getProxyTrustIterator()
Returns an iterator that produces the bootstrap proxy as the only element of the iteration.

Returns:
an iterator that produces the bootstrap proxy as the only element of the iteration

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Verifies that the main proxy is an instance of TrustEquivalence, and that the bootstrap proxy is an instance of both RemoteMethodControl and TrustEquivalence.

Throws:
InvalidObjectException - if the main proxy is not an instance of TrustEquivalence, or the bootstrap proxy is not an instance of both RemoteMethodControl and TrustEquivalence
IOException
ClassNotFoundException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.