Top Description Fields Constructors Methods
java.security

public Class GuardedObject

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.IOException

A GuardedObject is an object that is used to protect access to another object.

A GuardedObject encapsulates a target object and a Guard object, such that access to the target object is possible only if the Guard object allows it. Once an object is encapsulated by a GuardedObject, access to that object is controlled by the getObject method, which invokes the checkGuard method on the Guard object that is guarding access. If access is not allowed, an exception is thrown.

Authors
Roland Schemers, Li Gong
Since
1.2
See Also
Guard, Permission

Field Summary

Modifier and TypeField and Description
private final Guard
guard

The guard object.

private final Object
object

The object we are guarding.

private static final long

Constructor Summary

AccessConstructor and Description
public
GuardedObject(Object
the object to be guarded.
object
,
Guard
the Guard object that guards access to the object.
guard
)

Constructs a GuardedObject using the specified object and guard.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the guarded object.
getObject
()

Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Writes this object out to a stream (i.e., serializes it).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

guardback to summary
private final Guard guard

The guard object.

Annotations
@SuppressWarnings:serial
objectback to summary
private final Object object

The object we are guarding.

Annotations
@SuppressWarnings:serial
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

GuardedObjectback to summary
public GuardedObject(Object object, Guard guard)

Constructs a GuardedObject using the specified object and guard. If the Guard object is null, then no restrictions will be placed on who can access the object.

Parameters
object:Object

the object to be guarded.

guard:Guard

the Guard object that guards access to the object.

Method Detail

getObjectback to summary
public Object getObject() throws SecurityException

Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard.

Returns:Object

the guarded object.

Exceptions
SecurityException:
if access to the guarded object is denied.
writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Writes this object out to a stream (i.e., serializes it). We check the guard if there is one.

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs