Java Authorized Insider __java

Source: Internet
Author: User

In the field of information security, authorization is the center of the world because it is the process of controlling the access of individuals, processes, and computers to system resources. Until recently, the question associated with the Java security architecture was "what is the access rights of this running code." "This situation has changed with the introduction of Java Authentication and authorization services (Java authentication and Authorization Service,jaas)." JAAS is first expanded as a JDK version 1.3 platform, and then as a core part of JDK 1.4 and later versions. In JAAS, the question becomes "what is the access rights of the authenticated user who is running this code." ”

In this article, you will also introduce the old code-centric Java authorization architecture and the new user-centric architecture. I'll start with an overview of the Java 2 Platform security architecture, focusing on how the architecture leverages two basic concepts-security policies and protection domains-to define, organize, and aggregate static and/or dynamic access rights. It then analyzes the underlying mechanism of runtime access checking for the Java 2 Platform security architecture in detail, including the stack check and the traversal (traversal) mechanism that determines whether permissions are granted. After understanding how the code-centric authorization model works, I will turn to the user-centric authorization model for Java licensing and authentication Services (JAAS). Here, I focus on the concept of subject access control, and show how it was implemented on the stack checker mechanism of the original Java 2 Platform security architecture in JAAS.

Note that this article assumes that the reader is familiar with application programming on the Java platform (J2SE SDK 1.4) and the basic concepts of enterprise application security. All the concepts associated with the code-centric and user-centric authorization architecture of the Java platform are described only. code-centric authorization


The Java platform is traditionally used to run mobile code, such as applets. To protect system resources from any arbitrary code fragments downloaded from the network to the user's browser, applets is restricted to a sandbox where they run with a limited set of permissions. On the other hand, for local Java applications, few (if any) installations will provide a security manager similar to the sandbox environment. Therefore, local applications are generally trusted to access all system resources.

The biggest difference between the JDK 1.x model and the new security architecture of the Java 2 platform SDK version 1.2 is the introduction of a new, configurable security policy that enables fine-grained and manageable access control. All code, whether local or downloaded, whether signed or unsigned, can be constrained by a well-defined security policy that grants (possibly overlapping) permissions to different code. At the same time, with the introduction of multiple process capabilities in the JVM (see Resources), there are requirements for user-based access control.

The rationale behind the Java 2 Platform security architecture can be summed up as follows: A system-level security policy defines access to the execution code that protects the domain organization (as required by the application). Security policy is used for access control checks, which are performed by the JVM at run time. In this tour guide, I will elaborate on these concepts in detail.

Back to the top of the page as a typed (typed) object


In the Java 2 Platform security architecture, all access permissions are typed and hierarchical, and their roots are abstract class java.security.Permission. Usually a permission contains a target ("Who will execute the operation controlled by this permission.") ") and an operation (" If this permission allows, what will be done with this target. ") ”)。

In the context of allowing a running code to perform a specific "action" on a particular "target", an important concept is that the code is not necessarily granted the exact same Permission as needed. On the contrary, as long as you can infer or imply the required Permission from the Permission that is actually granted to this piece of code. For example, if a section of the Run code grants permission to read all files in the directory/x, it does not need explicit permissions to/x/in.xtx the destination file, because the previous permission implies the latter.

Obviously, the definition of whether a Permission implies another Permission depends on how the two Permission are defined. At a minimum, these two Permission must be of the same type. However, the runtime cannot be expected to make further judgments, and this implied inference logic must be assigned to the Permission class involved. The runtime queries the implied inference logic of the Permission class by invoking a method that is appropriately named implies. permissions to aggregate


The new security architecture also introduces the concept of aggregation (aggregation). On the Java 2 platform, multiple instances of the same type of Permission object can be aggregated. A set of this type is called PermissionCollection. For example, a permissioncollection might contain two java.io.FilePermission instances that represent the privilege of reading two different files.

Such typed objects cleanly encapsulate the ability to create and maintain a set merging and traversing this collection. Instead of calling the implies () method individually for each object each time you want to check permissions, the Java runtime simply invokes the implies () method provided by the PermissionCollection object and waits for its response. You can define a new permissioncollection type for each custom permission object that you create. Of course, the exact implementation of the implies () method in permissioncollection depends on the attributes of the given Permission object. Permissions Objects


In addition to having multiple instances of a particular Permission type, any given section of the run code will get different types of Permission. The Java 2 Platform security architecture provides a set of PermissionCollection objects in the form of a permissions object. A Permissions object is a collection of collections of a single Permission instance. The Permissions class also provides a implies () method. Remember, however, that in order for one Permission to imply another, they must be of the same type. Therefore, invoking the implies () method of the Permissions object causes the latter to first locate the correct permissioncollection instance in its internal collection (that contains an instance of a permission object of the correct set of types) and then invoke the resulting PermissionCollection the implies () method of the object, passing it the Permission to check.

Back to the top of the page security policy and protection domain


The security policy that applies to a system is essentially a well-defined "warehouse" that stores assertions that grant access to different entities in the system. According to the classic definition of protected domain (see Resources), a domain is defined by a set of objects that are directly accessible by an entity currently authorized in the system (by this definition, the Java in version 1.1 of JDK can actually be protection The sandbox is imagined as a protected domain with a fixed boundary. The Java 2 Platform security policy built on this basis is designed to grant access based on Protectiondomain, rather than to authorize this permission for a single section of code running. Therefore, each class or object "belongs" to a protectiondomain, and security policy grants some access to this protected domain. Reaffirming Protectiondomain's view, a particular protectiondomain encapsulates a set of classes (for example, all classes loaded from a specific location and signed with a specific key), and their instances are granted the same set of permissions.

The reason behind this indirection (that is, permissions are not directly granted to classes and objects) is extensibility-it should be possible to change and/or refine the definition that constitutes protectiondomain without affecting the grant of permissions. (Indeed, the protectiondomain before Jaas is described only by code that belongs to it, and the Protectiondomain after Jaas is also described by authenticated users who run the code.) Because each user is assigned a specific protectiondomain that sets his or her permissions, user authentication allows a given piece of code to run with a different set of permissions depending on the currently authenticated user. I'll give you a more detailed description of all this when I discuss the JAAS authorization architecture. ) protects domains and code sources


Obviously, you must be able to uniquely identify a piece of running code to ensure that its access rights are not conflicting. The unique identity property of the running code has two items: the source of the code (the URL to which the code is loaded into memory) and the signer entity of the code (specified by a set of public keys that correspond to the digital signatures that run the code). The combination of these two features is written in the Java 2 Platform security architecture as a codesource for the given running code. It is now possible to provide a more rigorous definition of Protectiondomain: Protectiondomain is a set of codesource and their access rights. In other words, Protectiondomain represents all permissions granted to a particular codesource.

The Java runtime sets the mapping between Protectiondomain and the permissions granted to it through a class named Java.security.Policy (a specific extension). The default extension of this class is sun.security.provider.PolicyFile. As its name suggests, Sun.security.provider.PolicyFile obtains a mapping between the Codesource (the location URL and signer identity alias) and the permissions granted to it from a file. The location of this file can be supplied to the JVM as input through the environment variable java.security.policy. The Policy class provides a method named GetPermissions () that can be invoked to obtain a set of permissions that are granted to a particular codesource. Secureclassloader


A mapping between a class and   its protectiondomain  is set when the class is first loaded and does not change until the class is garbage collected. A class is typically loaded by a special class named secureclassloader .  SecureClassLoader  first load the byte from the corresponding URL, and verify the digital signature of the enclosing document file if necessary. It then invokes the above  getpermissions ()   method to obtain an heterogeneous   that is granted the  CodeSource  of the class with static binding permissions;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.