JavaTM security architecture 5

zhaozj2021-02-08  296

JavaTM security architecture (JDK1.2) 5. Safety type loading

Dynamic class load is an important feature of Java virtual machines because it provides a Java platform with a power to install software at runtime. It has many unique nature. First, the inert load represents the same demand and is loaded in the last minute; second, by increasing the link (it instead of some runtime check, "only once), the dynamic class is loaded to maintain the type of Java virtual machine. Safety; again, programmers can define their own class-loader. For example, specify some remote locations, where to load certain classes, or all of which assign appropriate security properties. Finally, the class loader can provide a separate namespace for a variety of software components. For example, a browser can load Applets from different web pages using a separate class loader, which maintains a certain degree of isolation between those Applet classes. In fact, these classes can include the same class with the name - these classes are treated with the Java virtual machine as a distinct type.

The type load mechanism is not only an important dynamic characteristic of the Java programming language, but also has a key role in ensuring security. The reason is that the class loader is responsible for the positioning and extraction, security policies of the class, and the task such as the appropriate license definition class object.

5.1 class loader level

When loading a class, because there may be multiple type loader instances in a Java virtual machine, an important issue is how to determine which type loader used. JDK1.2 introduces a multi-class loader class with unique performance, and another important problem is which type of type-loaded load we should use.

The root of the class loader class level is an abstract class called java.lang.classloader, which was originally defined in JDK1.0, and after this, further expansion. Class java.security.secureClassLoader is introduced in JDK1.2, which is subclass of this abstract ClassLoader class and a specific implementation. Class Java.Net.urclassLoader is a subclass of SecureClassLoader.

A utility called AppletViewer uses a private class Sun.Applet.AppletClassLoader to load Applets. In JDK1.0, AppletClassLoader is a subclass of ClassLoader and a concrete implementation. In JDK1.2, it is a subclass of UrlclassLoader.

When you create a user-customized class loader class, you can create subclasses from any of the above loaders, depending on the special needs of the user-class loader. Because AppletClassLoader is a dedicated class defined in the Sun. * Pack, it is not supported and may be changed, so it should not be created by it.

5.2 Original loader

Because each class is loaded by its class loader, and each type loader itself is a class, it must be loaded by another class loader, and we seem to have encountered obvious chicken and egg problems. That is to say, where is the first type loader coming? A "original" loader unspeuses the problem of this class loading. Original loaders typically write (such as C language) in this unit, and does not indicate itself in the Java context. Original loaders often load classes in a platform-dependent manner from a local file system.

Some classes, such as: those defined in the Java. * Package, which is important to complete the Java virtual machine and runtime system, which are often referenced as base classes. Due to historical reasons, all such classes have an null-type loader that may be a unique tag that the original loader exists. In fact, it is easy to treat the null-type loader as the original loader.

If you give all kinds of classes in a Java application environment, we can easily form a class load tree to reflect the relationship between class loads, each of which is not a class-loaded class is a leaf node, each class The parent node is its type loader, and the null value loader is root. Because this structure is not a loop, this structure is a tree - a class loader is not possible to load its ancestors, 5.3-type loading loader authorization

When a class loader is required to load a class, this class loader can load this class yourself or require additional type loaders to load this class. In other words, the first class loader can be authorized to the second type loader, the authorization relationship is virtual in a certain sense, which is not related to which type loader loads which other class loader. When the class loader object is created, the authorization relationship is formed (and is in the form of a parent-child relationship). However, the system class loader is all kinds of loaders authorized root ancestors. It must be taken to ensure that this authorization relationship does not include a loop, otherwise the authorization process may enter a dead cycle.

5.4 class analysis algorithm

JDK 1.2 ClassLoader's method is loaded with a class of default, in order of sequential sequential

Check that this class has been loaded. If the current class loader has a designated authorized father, authorize this class to load this class. If there is no parent, you will be authorized to the original type loader. A class that can be userized to search for other places.

The first step here is to query the local cache of the class loader (or its functional equivalents, such as global cache) to confirm whether the class to be loaded is matched with the target class. The last step provides a way to make a mechanism for the search class. In this way, the user-class loader can overwrite this method to indicate how a class should be queried. For example, an Applet class load can override this method to load the class through the network.

If you find this class in any step, it is returned; if you don't find the class using the above steps, an exception classNotFound is thrown out.

Type security is very important, the same class can only be loaded once by the same type of loading. If this class is not one of those already loaded, the current type loader tries to authorize this task to the parent class loader. This situation can be pushed. It guarantees to use the appropriate type loader. For example, when loading a system class, the authorization process will be pushed all the way before arriving at the system class loader.

We have known the authorization algorithm earlier. However, suppose gives the name of any class, which class loader should we start to load this class? The rules about determining the type loader are as follows:

When loading the first class of an application, use a new instance of URLClassLoader; when loading an applet, use a new instance of AppletClassLoader; when java.lang.classforname is directly called, use the original Class loader; When the request is loaded with a class is triggered in the existing class, the class loader is loaded with the existing class loader.

Note: There are some exceptions to the rules that use the URLClassLoader and AppletClassLoader instances, and vary depending on the specific system environment. For example, a web browser may choose to use an existing AppletClassLoader to load Applet classes from the same web page.

Since the capacity of the type loader is extremely large, we strictly limit the examples of who will create a class loader. On the other hand, we expect to provide a simple mechanism for applications or Applets to indicate the URL address and load classes from these locations. We offer a static method to enable a variety of applications to create an instance of the URLClassLoader class, but there is no other loader type. ........ | Next | ......... Welcome to contact us: Webmaster@prc.sun.com Copyright 1997-1998 Sun (China) Company, Beijing South Gifts 16th Floor, Jianwei Building, No. 66 Road, ALL Rights Reserved.lege

转载请注明原文地址:https://www.9cbs.com/read-875.html

New Post(0)