⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicops.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ca.commons.jndi;

import java.util.Properties;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.logging.*;


/**
 * <p>The BasicOps class contains methods for performing basic
 * directory operations.  Errors are generally caught and handled locally,
 * although return codes usually indicate the general success status of
 * operations.  </p>
 * <p/>
 * <p>Two methods, error() and log() are defined.  These are intended to be
 * over-ridden by programs wishing application specific handling of these
 * (i.e. for more sensible user output than System.out.println()...).</p
 */

public class BasicOps extends JNDIOps
{
    private final static Logger log = Logger.getLogger(BasicOps.class.getName());

    protected int ldapVersion = -1;  // ldap version of the current connection (-1 = not connected)

    String errorMsg;                     //TE: a record of the last error msg.
    Exception errorException = null;     //TE: a record of the last exception.


    /**
     * Initialise a Basic Operation object with a context.
     */

    public BasicOps(DirContext c)
            throws NamingException
    {
        super(c);
        setLdapVersion(c.getEnvironment());
    }

    /**
     * Create a new BasicOps object, initialised
     * with an ldap context created from the connectionData,
     * and maintaining a reference to that connectionData.
     *
     * @param cData contains all the connection details.  (Effectively
     *              a structured form of the jndi environment object).
     */
    public BasicOps(ConnectionData cData)
            throws NamingException
    {
        super(cData.getJNDIEnvironment());
    }

    /**
     * Factory Method to create BasicOps objects, initialised
     * with an ldap context created from the connectionData,
     * and maintaining a reference to that connectionData.
     *
     * @param cData the details of the directory to connect to
     * @return a BasicOps object.
     */

    public static BasicOps getInstance(ConnectionData cData)
            throws NamingException
    {
        BasicOps newObject = new BasicOps(cData);
        return newObject;
    }

    /**
     * Open an initial context.
     * Will open an initial context which can then be used to construct a
     * BasicOps object. Note that this method may take some time to return.
     *
     * @param connectionData a data object contain all the connection details.
     */

    public static DirContext openContext(ConnectionData connectionData)
            throws NamingException
    {
        return openContext(connectionData.getJNDIEnvironment());
    }


    /**
     * This static ftn. can be used to open an initial context (which can then
     * be used to construct a BasicOps object).  Note that this ftn may take some
     * time to return...
     *
     * @param version       the LDAP Version (2 or 3) being used.
     * @param host          the LDAP server name.
     * @param port          the LDAP server port (default 389) being used.
     * @param user          the Manager User's DN - (is null if user is not manager)
     * @param pwd           the Manager User's password - (is null if user is not manager)
     * @param tracing       whether to set BER tracing on or not
     * @param referralType  the jndi ldap referral type: [follow:ignore:throw]
     * @param aliasHandling how aliases should be handled in searches ('always'|'never'|'find'|'search')
     * @return The created context.
     * @deprecated use getInstance() instead
     */

    public static DirContext openContext(int version, String host, int port, String user, char[] pwd,
                                         boolean tracing, String referralType, String aliasHandling)
            throws NamingException
    {
        if (host == null)
            throw new NamingException("Host not specified in openContext()!");

        if (port == 0) port = 389;

        return openContext(version, ("ldap://" + host + ":" + port), user, pwd, tracing, referralType, aliasHandling);
    }


    /**
     * Opens a simple default initial context, with no authentication, using version 3 ldap.
     *
     * @deprecated use getInstance() instead.
     */

    public static DirContext openContext(String url)
            throws NamingException
    {
        ConnectionData myData = new ConnectionData();
        myData.url = url;

        return openContext(3,
                url,
                "",
                null,
                false,
                null,
                null,
                false,
                null,
                null,
                null,
                null,
                null,
                null,
                false);
    }


    /**
     * Opens an initial context with (optional) authentication and configurable ldap version.
     *
     * @param version       the LDAP Version (2 or 3) being used.
     * @param url           a url of the form ldap://hostname:portnumber
     * @param managerUserDN the Manager User's distinguished name (optionally null if not used)
     * @param pwd           the Manager User's password - (is null if user is not manager)
     */
/*
   public static DirContext openContext(int version, String url, String userDN,
                                        char[] pwd, boolean tracing,
                                        String referralType, String aliasType,
                                        boolean useSSL, String cacerts, String clientcerts,
                                        char[] caKeystorePwd, char[] clientKeystorePwd,
                                        String caKeystoreType, String clientKeystoreType )
*/

    public static DirContext openContext(int version,
                                         String url,
                                         String managerUserDN,
                                         char[] pwd)
            throws NamingException
    {
        return openContext(version,
                url,
                managerUserDN,
                pwd,
                false,
                null,
                null,
                false,
                null,
                null,
                null,
                null,
                null,
                null,
                false);
    }


    /**
     * This static ftn. can be used to open an initial context (which can then
     * be used to construct a BasicOps object).  Note that this ftn may take some
     * time to return...
     *
     * @param version       the LDAP Version (2 or 3) being used.
     * @param url           a url of the form ldap://hostname:portnumber
     * @param userDN        the Manager User's distinguished name (optionally null if not used)
     * @param pwd           the Manager User's password - (is null if user is not manager)
     * @param tracing       whether to set BER tracing on or not
     * @param referralType  the jndi ldap referral type: [follow:ignore:throw] (may be null - defaults to 'follow')
     * @param aliasHandling
     * @return The created context.
     * @deprecated use getInstance() instead
     */

    public static DirContext openContext(int version, String url, String userDN, char[] pwd, boolean tracing, String referralType, String aliasHandling)
            throws NamingException
    {
        return openContext(version,
                url,
                userDN,
                pwd,
                tracing,
                referralType,
                aliasHandling,
                false,
                null,
                null,
                null,
                null,
                null,
                null,
                false);
    }
     /**
     * This static ftn. can be used to open an initial context (which can then
     * be used to construct a BasicOps object).  Note that this ftn may take some
     * time to return...
     *
     * @param version            the LDAP Version (2 or 3) being used.
     * @param url                a url of the form ldap://hostname:portnumber.
     * @param userDN             the Manager User's distinguished name (optionally null if not used).
     * @param pwd                the Manager User's password - (is null if user is not manager).
     * @param tracing            whether to set BER tracing on or not.
     * @param referralType       the jndi ldap referral type: [follow:ignore:throw] (may be null - defaults to 'follow').
     * @param aliasType          how aliases should be handled in searches ('always'|'never'|'find'|'search').
     * @param useSSL             whether to use SSL (either simple or client-authenticated).
     * @param cacerts            the file containing the trusted server certificates (no keys).
     * @param clientcerts        the file containing client certificates.
     * @param caKeystorePwd      the password to the ca's keystore (may be null for non-client authenticated ssl).
     * @param clientKeystorePwd  the password to the client's keystore (may be null for non-client authenticated ssl).
     * @param caKeystoreType     the type of keystore file; e.g. 'JKS', or 'PKCS12'.
     * @param clientKeystoreType the type of keystore file; e.g. 'JKS', or 'PKCS12'.
     * @return The created context.
      * @deprecated use longer version with 'useGSSAPI' option instead.
     */

    public static DirContext openContext(int version,
                                         String url,
                                         String userDN,
                                         char[] pwd,
                                         boolean tracing,
                                         String referralType,
                                         String aliasType,
                                         boolean useSSL,
                                         String cacerts,
                                         String clientcerts,
                                         char[] caKeystorePwd,
                                         char[] clientKeystorePwd,
                                         String caKeystoreType,
                                         String clientKeystoreType)
            throws NamingException
    {
     return openContext(version,
                url,
                userDN,
                pwd,
                tracing,
                referralType,
                aliasType,
                useSSL,
                cacerts,
                clientcerts,
                caKeystorePwd,
                clientKeystorePwd,
                caKeystoreType,
                clientKeystoreType,
                false);
    }

    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -