|
ドキュメントの目次 |
このようなクライアントの例として、Java オブジェクト直列化サービス、オブジェクトインスペクタおよびデバッガなどの開発ツール、データベース持続機構などのアプリケーションがあります。
解決策
Java 1.2 では、フィールド、メソッド、またはコンストラクタオブジェクトは、デフォルトの Java 言語アクセス制御を抑制するよう明示的にフラグがたてられています。リフレクトされたオブジェクトを使用する場合、このフラグ (新しいインスタンスフィールド) をアクセス検査の一部として調べます。フラグが true の場合、アクセス検査は無効にされ、要求された操作が続行されます。 false の場合には、Java 1.1 で行われたような標準アクセス検査が実行されます。リフレクトされたメンバまたはコンストラクタでは、デフォルトのフラグは false に設定されています。
フラグ設定は、新しい Java 1.2 のセキュリティ機構によりセキュリティチェックが行われます。この操作を実行するには、クライアントのコンテキスト呼び出しに十分な特権が与えられている必要があります。
このため、Java 1.2 では、実際にリフレクトされたクラス (フィールド、メソッド、およびコンストラクタ) は、次で説明する新しい基底クラスである AccessibleObject クラスを継承します。このクラスは、リフレクトされたオブジェクトに accessible フラグを設定および取得するために必要な状態およびメソッドを提供します。次で説明する新しい ReflectPermission クラスは、セキュリティポリシーファイルを使用して必要な権限を与える能力を提供します。
プログラミングインタフェース
package java.lang.reflect;
/**
* The AccessibleObject class is the base class for Field, Method and
* Constructor objects. It provides the ability to flag a reflected
* object as suppressing default Java language access control checks
* when it is used. The access checks--for public, default (package)
* access, protected, and private members--are performed when Fields,
* Methods or Constructors are used to set or get fields, to invoke
* methods, or to create and initialize new instances of classes,
* respectively.
*
* <p>Setting the <tt>accessible</tt> flag in a reflected object
* permits sophisticated applications with sufficient privilege, such
* as Java Object Serialization or other persistence mechanisms, to
* manipulate objects in a manner that would normally be prohibited.
*
* @see Field
* @see Method
* @see Constructor
* @see ReflectPermission
*
* @since JDK1.2
*/
public
class AccessibleObject {
/**
* Convenience method to set the <tt>accessible</tt> flag for an
* array of objects with a single security check (for efficiency).
*
* @param array the array of AccessibleObjects
* @param flag the new value for the <tt>accessible</tt> flag in each object
* @throws SecurityException if the request is denied
*/
public static void setAccessible(AccessibleObject[] array, boolean flag)
throws SecurityException;
/**
* Set the <tt>accessible</tt> flag for this object to
* the indicated boolean value. A value of <tt>true</tt> indicates that
* the reflected object should suppress Java language access
* checking when it is used. A value of <tt>false</tt> indicates
* that the reflected object should enforce Java language access checks.
*
* @param flag the new value for the <tt>accessible</tt> flag
* @throws SecurityException if the request is denied
*/
public void setAccessible(boolean flag) throws SecurityException;
/**
* Get the value of the <tt>accessible</tt> flag for this object.
*/
public boolean isAccessible();
/**
* Constructor: only used by the Java Virtual Machine.
*/
protected AccessibleObject();
}
package java.lang.reflect;
/**
* The Permission class for reflective operations. A
* ReflectPermission is a <em>named permission</em> and has no
* actions. The only name currently defined is <tt>access</tt>,
* which allows suppressing the standard Java language access checks
* --for public, default (package) access, protected, and private
* members--performed by reflected objects at their point of use.
*
* <p>An example of permitting the identity "Duke" to suppress the
* language access checking for reflected members might be:
* <code>
* grant signedBy "Duke" {
* java.lang.reflect.ReflectPermission "access";
* }
* </code>
*
* @see java.security.Permission
* @see java.security.BasicPermission
* @see AccessibleObject
* @see Field#get
* @see Field#set
* @see Method#invoke
* @see Constructor#newInstance
*
* @since JDK1.2
*/
public final
class ReflectPermission extends java.security.BasicPermission {
/**
* Constructs a ReflectPermission with the specified name.
*
* @param name the name of the ReflectPermission
*/
public ReflectPermission(String name);
/**
* Constructs a ReflectPermission with the specified name and actions.
* The actions should be null; they are ignored.
*
* @param name the name of the ReflectPermission
* @param actions should be null.
*/
public ReflectPermission(String name, String actions);
}
|
Copyright © 1995-97 Sun Microsystems, Inc. All Rights Reserved. |
Java ソフトウェア |