public class BasicProxyPreparer extends Object implements ProxyPreparer, Serializable
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:
AdvisoryDynamicPermissions
Modifier and Type | Field and Description |
---|---|
protected MethodConstraints |
methodConstraints
Method constraints to use when verifying if proxies are trusted and for
setting their constraints, if
methodConstraintsSpecified is
true . |
protected boolean |
methodConstraintsSpecified
Whether to use
methodConstraints when verifying if proxies are
trusted and for setting their constraints. |
protected boolean |
verify
Whether to verify if proxies are trusted.
|
Constructor and Description |
---|
BasicProxyPreparer()
Creates a proxy preparer that specifies not to verify proxies, grant
them permissions, or set their constraints.
|
BasicProxyPreparer(AtomicSerial.GetArg arg)
AtomicSerial constructor
|
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.
|
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Returns
true if the given object is an instance of the same
class as this object, with the same value for verify , with
method constraints that are equals or similarly not
specified, and with permissions containing the same
elements, independent of order. |
protected MethodConstraints |
getMethodConstraints(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 void |
grant(Object proxy)
Grants permissions to the proxy.
|
int |
hashCode()
Returns a hash code value for this object.
|
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 Object |
setConstraints(Object proxy)
Sets constraints on the proxy.
|
String |
toString()
Returns a string representation of this object.
|
protected void |
verify(Object proxy)
Verifies that the proxy is trusted.
|
protected final boolean verify
protected final boolean methodConstraintsSpecified
methodConstraints
when verifying if proxies are
trusted and for setting their constraints.protected final MethodConstraints methodConstraints
methodConstraintsSpecified
is
true
. Set to null
if
methodConstraintsSpecified
is false
.public BasicProxyPreparer()
public BasicProxyPreparer(boolean verify, Permission[] permissions)
verify
- whether to verify if proxies are trustedpermissions
- permissions to grant, or null
if no
permissions should be grantedNullPointerException
- if permissions
is not
null
and any of its elements are null
public BasicProxyPreparer(boolean verify, MethodConstraints methodConstraints, Permission[] permissions)
verify
- whether to verify if proxies are trustedmethodConstraints
- method constraints to use when verifying
and setting constraintspermissions
- permissions to grant, or null
if no
permissions should be grantedNullPointerException
- if permissions
is not
null
and any of its elements are null
public BasicProxyPreparer(AtomicSerial.GetArg arg) throws IOException
arg
- IOException
protected MethodConstraints getMethodConstraints(Object proxy)
The default implementation returns the value of methodConstraints
if methodConstraintsSpecified
is
true
, else returns the constraints on the specified proxy
if it implements RemoteMethodControl
, else returns
null
.
Subclasses may wish to override this method, for example, to augment the existing constraints on the proxy rather than replacing them.
proxy
- the proxy being preparedprotected Permission[] getPermissions(Object proxy)
null
.
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. Note if no permissions have been specified, this method attempts to detect any advisory permissions.
proxy
- the proxy being preparedpublic Object prepareProxy(Object proxy) throws RemoteException
The default implementation provides the following behavior. If
proxy
is null
, throws a NullPointerException
. Otherwise, calls verify
with proxy
. If the verify
call succeeds, calls
grant
with proxy
. If the grant
call succeeds, returns the result of calling setConstraints
with proxy
.
Note the grant
call will only dynamically grant
permissions if the current context has the relevant GrantPermission's
in a security policy file.
Subclasses may wish to override this method, for example, to perform
additional operations, typically calling the default implementation via
super
.
prepareProxy
in interface ProxyPreparer
proxy
- the proxy to prepareNullPointerException
- if proxy
is null
RemoteException
- if a communication-related exception occursSecurityException
- if a security exception occursverify
,
grant
,
setConstraints
protected void verify(Object proxy) throws RemoteException
prepareProxy
.
The default implementation provides the following behavior. If
proxy
is null
, throws a NullPointerException
. Otherwise, if verify
is
true
, calls Security.verifyObjectTrust
, with proxy
, null
for the class loader, and, for the context, a collection containing the
result of calling getMethodConstraints
with proxy
, or an empty collection if the constraints are
null
.
Subclasses may wish to override this method, for example, to specify a different class loader or context when verifying the proxy.
proxy
- the proxy to verifyNullPointerException
- if proxy
is null
RemoteException
- if a communication-related exception occursSecurityException
- if verifying that the proxy is trusted failsprepareProxy
,
getMethodConstraints
,
Security.verifyObjectTrust
protected void grant(Object proxy)
prepareProxy
unless verify
throws an exception.
The default implementation provides the following behavior. If
proxy
is null
, throws a NullPointerException
. Otherwise, calls getPermissions
with proxy
to determine what permissions
should be granted. If the permissions are not empty, calls Security.grant
, with the proxy's
class as the class argument and those permissions. If grant
discovers that dynamic permission grants are not supported and throws a
UnsupportedOperationException
, catches that exception and throws
a SecurityException
.
Subclasses may wish to override this method, for example, to alter the principals for which permission grants are made.
proxy
- the proxy to grant permissionsSecurityException
- if a security exception occursNullPointerException
- if proxy is null
prepareProxy
,
getPermissions
,
Security.grant
protected Object setConstraints(Object proxy)
prepareProxy
unless verify
or grant
throw an exception.
The default implementation provides the following behavior. If
proxy
is null
, throws a NullPointerException
. Otherwise, if methodConstraintsSpecified
is false
, returns the proxy, else if object does not
implement RemoteMethodControl
, throws a SecurityException
, else returns the result of calling RemoteMethodControl.setConstraints
on the proxy, using the value returned from calling getMethodConstraints
with proxy
.
Subclasses may wish to override this method, for example, to support
verifying objects that do not implement RemoteMethodControl
.
proxy
- the proxyNullPointerException
- if proxy
is null
SecurityException
- if a security exception occursprepareProxy
,
getMethodConstraints
,
RemoteMethodControl.setConstraints
public String toString()
public boolean equals(Object object)
true
if the given object is an instance of the same
class as this object, with the same value for verify
, with
method constraints that are equals
or similarly not
specified, and with permissions
containing the same
elements, independent of order.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.