Name
GuardedObject
Synopsis
This class uses a Guard
object to guard against unauthorized access to an arbitrary
encapsulated object. Create a GuardedObject
by
specifying an object and a Guard
for it. The
getObject( )
method calls the checkGuard( )
method of the
Guard
to determine whether access to the object
should be allowed. If access is allowed, getObject(
)
returns the encapsulated object. Otherwise, it throws a
java.lang.SecurityException
.
The Guard
object used by a
GuardedObject
is often a
Permission
. In this case, access to the guarded
object is granted only if the calling code is granted the specified
permission by the current security policy.
Figure 14-11. java.security.GuardedObject
public class GuardedObject implements Serializable { // Public Constructors public GuardedObject(Object object, Guard guard); // Public Instance Methods public Object getObject( ) throws SecurityException; }
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.