Jndi Basic Concepts

Source: Internet
Author: User
Tags ldap

Java Naming and Directory Interface

Java Naming and Directory interfaces

  • Naming concepts
    Naming services: Make different objects contact by name
    When we send an email, the system uses the email address we provide to find a corresponding system object.

    The main function of naming is to map a simple name to a complex object.
    For example: DNS mapping
    Www.baidu.com ==> 61.135.169.125
    System file Mapping:
    C:\bin\autoexec.bat ==> File Reference
    From the above two examples, we can see that the naming service is widely used in our life.
  • Names
    The name of the naming system must follow the appropriate system syntax: A name that represents a component, different components that are associated with rules that require the use of conventions, are associated with delimiters

    In UNIX systems, paths are separated by "/" and "/" represents different directories (files)
    DNS uses "." To associate
    Lightweight Directory Access Protocol (LDAP) uses "," to split different components, each using "=" to split the name and value
  • Bindings
    Binding: A name associated with an object
    A filename binds a file, a domain name binds an IP address, an LDAP name binds an LDAP entity ...
  • References and Addresses
    Depending on the naming service, some objects cannot be directly stored by the naming service, that is, a copy of an object cannot be placed in the naming service. Instead, they must be referenced for storage; that is, a pointer or reference to an object is placed in the naming service, and a reference represents information about how to access the object. Typically, it is a compact representation that can be used to communicate with an object, and the object itself may contain more state information.
  • Context
    A context is a set of bindings for names and objects, each of which has its own naming convention. A context provides a search function to return a binding object, and the context usually also provides binding name ~ Unbind Name ~ Lists the features that bind the name. An object in a context can also be bound to another context object (called Subcontext), and they have the same naming convention.

    Every file directory in Unix, in the context of UNIX, a file directory (sub) can be named for a subdirectory relative to another file directory (parent), which is the subcontext of USR.
  • Naming Systems and namespaces
    A naming system is a connected set of the same type of context (they have the same naming convention) and provides a common set of actions.
    The naming system provides a naming service for its customers to perform naming-related operations. Access the naming service through its own interface.
    A namespace is a collection of all the possible names in a named system.
  • Directory Concepts

    Many naming services extend to a directory service. The Directory service associates names with objects and can also be associated with properties of those objects
    Directory service = Naming Service + objects (directory objects)
    Not only can you find an object by its name, you can also get the properties of an object or search for an object based on its properties.

    To give a phone book directory service, a user name can be mapped to a person, a person has an address ~ mobile phone number ~ Mailbox ... Attribute information, where the person is a directory object, in this directory object can store a lot of information (attributes), this information can be obtained through the name of the person.
    Directory object: Catalog objects contain many properties used to describe its own

    • Attributes
      A directory object can contain many properties
    • Directories and Directory Services
      A directory is a set of connected directory objects
      The directory service is a property operation that provides the creation, addition, deletion, and modification of properties associated with objects in the directory. Access the service through its own interface.
    • Search Service
      Provide the directory service with a name to get a directory object, in addition, there are some directories, such as LDAP is to support the search for the gratitude, when you go to search a directory object, You can use a name or use a logical expression to indicate the properties of the directory object to get the object. This search is called a search filter. This style of search is sometimes referred to as reverse lookup or content-based search. The Directory service search returns the object that satisfies the search filter.
      • Combining naming and Directory Services
        Directories often arrange for their objects to form a hierarchy, for example, all objects in an LDAP directory are made up of a tree structure, called the Directory Information Tree (directory information trees). Inside this DIT, An organization object may contain group objects and may contain personal objects, and when directory objects are arranged in this manner, they can be used as a context in the container's properties.
  • Jndi

    Java Naming and directory interface? (JNDI) is an application programming interface (API) that provides naming and directory functionality. It is defined as an implementation independent of any particular directory service, so any directory service that has been deployed can be accessed in a common way.

    • Architecture
      The JNDI schema includes an API and a service Provider Interface (SPI), which Java applications use to access various naming and directory services using the Jndi API. The SPI causes the various naming and directory services to leak out and transparently, allowing Java applications to use the Jndi API to access their services. See
    • Packaging
      Jndi is included in the Java SE platform. With Jndi, you must have a Jndi class and one or more service providers. The JDK includes service providers for the following naming and directory services:

      • Lightweight directories Access Protocol (LDAP) (Lightweight Directory Access Protocol)
      • Common Object Request Broker Architecture (CORBA) Common object Services (COS) Name Service (Common Object Request Broker architecture)
      • Java Invocation (RMI) Registry (Java Remote method invocation)
      • Domain Name Service (DNS)
        Jndi is divided into five packages:
      • Javax.naming
      • Javax.naming.directory
      • Javax.naming.ldap
      • Javax.naming.event
      • Naming package
        The java.naming contains classes and interfaces that access the naming service.
    • Context
      The Java.naming.Context interface is a core interface that provides search/bind/Unbind, rename objects/create/Destroy Subcontext.
      Lookup:lookup (name/string): The most common search operation, passing in a name that you want to search, returns an object bound to that name.
      Bindings:listbindings (name/string) Returns an enumeration collection that is bound by Name-to-object, which contains the object name/object class name/object itself
      List:list (name/string) is similar to listbinding except that it returns an enumeration collection that contains the object name/object class name and does not contain the object itself. This list method is sometimes a useful operation, It will be more efficient and less expensive than listbinding when you just want to browse some of the object's information without including the object itself.
      Name:name is an interface that represents a common name, an ordered sequence of 0 or more components. The naming system uses this interface to define the contract names that follow its description in the naming and catalog concepts.
      References: Objects are stored in different ways in the naming and directory service. A reference to an object can be a very concise representation. Jndi uses the reference class to represent a reference, a reference that contains a copy of how the object is constructed, and Jndi attempts to find and convert the Java object in the directory service to reference. This way the Jndi client has an illusion: Any Java object can be stored in the directory service.

    • The Initial Context
      All naming and directory operations in Jndi are relative to the context. There is no absolute root path, so Jndi declares a initialcontext, which provides a starting pointer for easy naming and directory manipulation, once you have a initialcontext, You will rely on it to look for other context and objects.
    • Exceptions.
      Jndi defines a hierarchy of exception mechanisms that can handle any errors in naming and directory operations. The root of this anomaly mechanism is namingexception.
    • Directory Package
      The Javax.naming.directory Package Inheritance Javax.naming package provides the ability to access the directory service but not the naming service. This package allows the application to retrieve objects stored in the directory and use the specified properties to search for objects.
    • The Directory Context
      The Javax.naming.directory.DirContext interface represents a context for a directory. DirContext can also be used as a naming context by inheriting Javax.naming.Context. This means that any directory object can also provide a naming context. It defines a method for checking and updating the properties of a directory entry.
      • Attributes
        You use the GetAttributes () method to retrieve the property associated with the catalog item (the name you provide). Use Modifyattributes () to modify the properties. You can add, replace, or delete properties and property values.
      • Searches
        DirContext contains a directory-based search method. The simplest and most common usage, the application provides a set of value that matches the specified property to the search () method for the target object. Other methods of overloading search () can support more complex filter searches.
    • LDAP Package
      JAVAX.NAMING.LDAP covers Javax.naming.directory and provides functionality classes and interfaces that are specific to LDAP V3. In fact, most applications use the Javax.naming.directory package enough to find LDAP without using the JAVAX.NAMING.LDAP package. This package is mainly used for those who need to use "extended" operations, controls, unsolicited notifications.
      • "Extended" Operation
        In addition to some clear operations, such as search and modification, LDAP V3 (RFC 2251) specifies a way to pass an operation that has not yet been defined between the LDAP client and the server. These operations are referred to as "extended" operations. An "extended" operation can be defined by a standard organization, such as the Internet Engineering Task Force (IETF) or by a vendor.
      • Controls
        LDAP V3 allows any request or response to undefined modifiers. A control that sends a request is a request control, and a control sends a response that is a response control. A control may be defined by a standard organization, such as the Internet Engineering Task Force (IETF) or through a vendor. The request control and the response control do not have to be paired, that is, there is no need to send a response control for each request control, and vice versa.
      • Unsolicited notifications
        In addition to the normal request/response mode of interaction between the client and the server, LDAP V3 also provides unsolicited notification messages-sent asynchronously from the server to the client without requiring any requests.
    • The LDAP Context
      The Ldapcontext interface is a context in which operations can be extended. Send Request control/Receive response control.
    • The
    • Event package
      Javax.naming.event contains classes and interfaces that support naming and directory service event notifications.

      The
      • Events
        Namingevent is an event generated by a naming/directory service. The event contains the event type. For example, some event types can affect the event of a namespace, such as "object additions," while others cannot, such as "Object changes." The
      • Listeners
        Naminglistener is an object that listens to Namingevent. Each type of namingevent has a naminglistener corresponding to it. For example, a Namespacechangelistener event that listens for namespace changes, An event that Objectchangelistener is used to listen for object changes.

      Accept time notifications, requiring listener to register a eventcontext or Eventdircontext. Once registered, the listener receives event notifications when the corresponding changes occur in the naming/directory service.

    • Service Provider Package
      The purpose of the JAVAX.NAMING.SPI package is to adapt to different naming and directory services, and any service can enter the application through Jndi.

      • Plug-in Architecture
        JAVAX.NAMING.SPI allows for different implementations of dynamic insertions, including those initial context and contexts.
      • Java Object Support
        JAVAX.NAMING.SPI: You can perform lookup () to return natural and intuitive Java objects. For example, if you look up a printer name from a directory, you might want to have a printer object that you can manipulate. This support is provided in the form of an object factory.
        The package also provides a reverse operation. That is Context.bind () can accept Java objects and store objects to the underlying naming/directory service. This support is provided in the form of a static factory.
      • Multiple naming Systems (Federation)
        Jndi operations allow applications to provide names that span multiple named systems. One service provider may need to interact with another service provider during the completion of an operation.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Jndi Basic Concepts

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.