Class BasicProxyPreparer
- All Implemented Interfaces:
Serializable,ProxyPreparer
ProxyPreparer for verifying that proxies are trusted, granting them dynamic
permissions, and setting their constraints, as well as for creating other proxy preparer
subclasses that include those operations. Applications and configurations can use this class to create proxy preparers for several common cases. Some examples include creating proxy preparers that:
- Verify trust, grant permissions, and set new constraints, to prepare a proxy received from an untrusted source.
- Use the proxy's existing constraints when verifying trust in the proxy, to prepare a trusted proxy received with integrity protection from a trusted source that supplies constraints, confirming that the proxy's implementation is trusted locally, but allowing the constraints to be downloaded from a third party.
- Set new constraints, to prepare a trusted proxy received with integrity protection from a trusted source that is not known to supply the appropriate constraints.
- Grant permissions, to prepare a trusted proxy received with integrity protection from a trusted source that supplies appropriate constraints, if the proxy needs permission grants.
- Do nothing, to use as a default when retrieving an optional configuration entry, or to prepare a non-secure proxy.
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MethodConstraintsMethod constraints to use when verifying if proxies are trusted and for setting their constraints, ifmethodConstraintsSpecifiedistrue.protected final booleanWhether to usemethodConstraintswhen verifying if proxies are trusted and for setting their constraints.protected final Permission[]Permissions to grant to proxies, or an empty array if no permissions should be granted.protected final booleanWhether to verify if proxies are trusted. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a proxy preparer that specifies not to verify proxies, grant them permissions, or set their constraints.BasicProxyPreparer(boolean verify, Permission[] permissions) Creates a proxy preparer that specifies whether proxies should be verified, using the constraints on the proxy by default, and specifies what permissions to grant to proxies.BasicProxyPreparer(boolean verify, MethodConstraints methodConstraints, Permission[] permissions) Creates a proxy preparer that specifies whether proxies should be verified, specifies permissions to grant them, and specifies what method constraints to use when verifying and setting constraints. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the given object is an instance of the same class as this object, with the same value forverify, with method constraints that areequalsor similarly not specified, and withpermissionscontaining the same elements, independent of order.protected MethodConstraintsgetMethodConstraints(Object proxy) Returns the method constraints to use when verifying and setting constraints on the specified proxy.protected Permission[]getPermissions(Object proxy) Returns the permissions to grant to proxies, or an empty array if no permissions should be granted.protected voidGrants permissions to the proxy.inthashCode()Returns a hash code value for this object.prepareProxy(Object proxy) Performs operations on a proxy to prepare it for use, returning the prepared proxy, which may or may not be the argument itself.protected ObjectsetConstraints(Object proxy) Sets constraints on the proxy.toString()Returns a string representation of this object.protected voidVerifies that the proxy is trusted.
-
Field Details
-
verify
protected final boolean verifyWhether to verify if proxies are trusted. -
methodConstraintsSpecified
protected final boolean methodConstraintsSpecifiedWhether to usemethodConstraintswhen verifying if proxies are trusted and for setting their constraints. -
methodConstraints
Method constraints to use when verifying if proxies are trusted and for setting their constraints, ifmethodConstraintsSpecifiedistrue. Set tonullifmethodConstraintsSpecifiedisfalse. -
permissions
Permissions to grant to proxies, or an empty array if no permissions should be granted. The value is always non-null.
-
-
Constructor Details
-
BasicProxyPreparer
public BasicProxyPreparer()Creates a proxy preparer that specifies not to verify proxies, grant them permissions, or set their constraints. -
BasicProxyPreparer
Creates a proxy preparer that specifies whether proxies should be verified, using the constraints on the proxy by default, and specifies what permissions to grant to proxies.- Parameters:
verify- whether to verify if proxies are trustedpermissions- permissions to grant, ornullif no permissions should be granted- Throws:
NullPointerException- ifpermissionsis notnulland any of its elements arenull
-
BasicProxyPreparer
public BasicProxyPreparer(boolean verify, MethodConstraints methodConstraints, Permission[] permissions) Creates a proxy preparer that specifies whether proxies should be verified, specifies permissions to grant them, and specifies what method constraints to use when verifying and setting constraints.- Parameters:
verify- whether to verify if proxies are trustedmethodConstraints- method constraints to use when verifying and setting constraintspermissions- permissions to grant, ornullif no permissions should be granted- Throws:
NullPointerException- ifpermissionsis notnulland any of its elements arenull
-
-
Method Details
-
getMethodConstraints
Returns the method constraints to use when verifying and setting constraints on the specified proxy.The default implementation returns the value of
methodConstraintsifmethodConstraintsSpecifiedistrue, else returns the constraints on the specified proxy if it implementsRemoteMethodControl, else returnsnull.Subclasses may wish to override this method, for example, to augment the existing constraints on the proxy rather than replacing them.
- Parameters:
proxy- the proxy being prepared- Returns:
- the method constraints to use when verifying and setting constraints on the proxy
-
getPermissions
Returns the permissions to grant to proxies, or an empty array if no permissions should be granted. The return value need not be newly created, but cannot benull.The default implementation returns the value of
permissions.Subclasses may wish to override this method, for example, to grant permissions that depend on principal constraints found on the proxy.
- Parameters:
proxy- the proxy being prepared- Returns:
- the permissions to grant to the proxy
-
prepareProxy
Performs operations on a proxy to prepare it for use, returning the prepared proxy, which may or may not be the argument itself.The default implementation provides the following behavior. If
proxyisnull, throws aNullPointerException. Otherwise, callsverifywithproxy. If theverifycall succeeds, callsgrantwithproxy. If thegrantcall succeeds, returns the result of callingsetConstraintswithproxy.Subclasses may wish to override this method, for example, to perform additional operations, typically calling the default implementation via
super.- Specified by:
prepareProxyin interfaceProxyPreparer- Parameters:
proxy- the proxy to prepare- Returns:
- the prepared proxy
- Throws:
NullPointerException- ifproxyisnullRemoteException- if a communication-related exception occursSecurityException- if a security exception occurs- See Also:
-
verify
Verifies that the proxy is trusted. Called by the default implementation ofprepareProxy.The default implementation provides the following behavior. If
proxyisnull, throws aNullPointerException. Otherwise, ifverifyistrue, callsSecurity.verifyObjectTrust, withproxy,nullfor the class loader, and, for the context, a collection containing the result of callinggetMethodConstraintswithproxy, or an empty collection if the constraints arenull.Subclasses may wish to override this method, for example, to specify a different class loader or context when verifying the proxy.
- Parameters:
proxy- the proxy to verify- Throws:
NullPointerException- ifproxyisnullRemoteException- if a communication-related exception occursSecurityException- if verifying that the proxy is trusted fails- See Also:
-
grant
Grants permissions to the proxy. Called by the default implementation ofprepareProxyunlessverifythrows an exception.The default implementation provides the following behavior. If
proxyisnull, throws aNullPointerException. Otherwise, callsgetPermissionswithproxyto determine what permissions should be granted. If the permissions are not empty, callsSecurity.grant, with the proxy's class as the class argument and those permissions. Ifgrantdiscovers that dynamic permission grants are not supported and throws aUnsupportedOperationException, catches that exception and throws aSecurityException.Subclasses may wish to override this method, for example, to alter the principals for which permission grants are made.
- Parameters:
proxy- the proxy to grant permissions- Throws:
SecurityException- if a security exception occursNullPointerException- if proxy isnull- See Also:
-
setConstraints
Sets constraints on the proxy. Called by the default implementation ofprepareProxyunlessverifyorgrantthrow an exception.The default implementation provides the following behavior. If
proxyisnull, throws aNullPointerException. Otherwise, ifmethodConstraintsSpecifiedisfalse, returns the proxy, else if object does not implementRemoteMethodControl, throws aSecurityException, else returns the result of callingRemoteMethodControl.setConstraintson the proxy, using the value returned from callinggetMethodConstraintswithproxy.Subclasses may wish to override this method, for example, to support verifying objects that do not implement
RemoteMethodControl.- Parameters:
proxy- the proxy- Returns:
- the proxy with updated constraints
- Throws:
NullPointerException- ifproxyisnullSecurityException- if a security exception occurs- See Also:
-
toString
Returns a string representation of this object. -
equals
Returnstrueif the given object is an instance of the same class as this object, with the same value forverify, with method constraints that areequalsor similarly not specified, and withpermissionscontaining the same elements, independent of order. -
hashCode
public int hashCode()Returns a hash code value for this object.
-