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

📄 jndiops.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public NamingEnumeration searchSubTree(Name searchbase, String filter, int limit,
                                           int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchSubTree(searchbase, filter, limit, timeout, returnAttributes);
    }

    protected NamingEnumeration rawSearchSubTree(Name searchbase, String filter, int limit,
                                                 int timeout, String[] returnAttributes) throws NamingException
    {
        if (returnAttributes != null && returnAttributes.length == 0)
            returnAttributes = new String[]{"objectClass"};

        /* specify search constraints to search subtree */
        SearchControls constraints1 = new SearchControls();

        constraints1.setSearchScope(SearchControls.SUBTREE_SCOPE);
        constraints1.setCountLimit(limit);
        constraints1.setTimeLimit(timeout);

        constraints1.setReturningAttributes(returnAttributes);
        SearchControls constraints = constraints1;

        return ctx.search(searchbase, filter, constraints);
    }


    /**
     * Performs a base object search (i.e. just a search of the current entry, nothing below it),
     * returning no attributes (i.e. just DNs);
     *
     * @param searchbase the domain name (relative to initial context in ldap) to seach from.
     * @param filter     the non-null filter to use for the search
     * @param limit      the maximum number of results to return
     * @param timeout    the maximum time to wait before abandoning the search
     * @return list of search results ('SearchResult's); entries matching the search filter.
     */

    public NamingEnumeration searchBaseEntry(Name searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return rawSearchBaseEntry(searchbase, filter, limit, timeout, new String[]{"objectClass"});
    }


    /**
     * Performs a base object search (i.e. just a search of the current entry, nothing below it).
     *
     * @param searchbase       the domain name (relative to initial context in ldap) to seach from.
     * @param filter           the non-null filter to use for the search
     * @param limit            the maximum number of results to return
     * @param timeout          the maximum time to wait before abandoning the search
     * @param returnAttributes an array of strings containing the names of attributes to search. (null = all, empty array = none)
     * @return list of search results ('SearchResult's); entries matching the search filter.
     */

    public NamingEnumeration searchBaseEntry(Name searchbase, String filter, int limit,
                                             int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchBaseEntry(searchbase, filter, limit, timeout, returnAttributes);
    }

    /**
     * This is the core method for all base entry searches.
     *
     * @param searchbase       the domain name (relative to initial context in ldap) to seach from.
     * @param filter           the non-null filter to use for the search
     * @param limit            the maximum number of results to return
     * @param timeout          the maximum time to wait before abandoning the search
     * @param returnAttributes an array of strings containing the names of attributes to search. (null = all, empty array = none)
     * @return list of search results ('SearchResult's); entries matching the search filter.
     */

    protected NamingEnumeration rawSearchBaseEntry(Name searchbase, String filter, int limit,
                                                   int timeout, String[] returnAttributes)
            throws NamingException
    {
        NamingEnumeration result = null;

        if (returnAttributes != null && returnAttributes.length == 0)
            returnAttributes = new String[]{"objectClass"};

        /* specify search constraints to search subtree */
        SearchControls constraints = new SearchControls();

        constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
        constraints.setCountLimit(limit);
        constraints.setTimeLimit(timeout);

        constraints.setReturningAttributes(returnAttributes);

        result = ctx.search(searchbase, filter, constraints);

        return result;
    }


    /**
     * Performs a base object search (i.e. just a search of the current entry, nothing below it),
     * returning no attributes (i.e. just DNs);
     *
     * @param searchbase the domain name (relative to initial context in ldap) to seach from.
     * @param filter     the non-null filter to use for the search
     * @param limit      the maximum number of results to return
     * @param timeout    the maximum time to wait before abandoning the search
     * @return list of search results ('SearchResult's); entries matching the search filter.
     */

    public NamingEnumeration searchBaseEntry(String searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return rawSearchBaseEntry(nameParser.parse(searchbase), filter, limit, timeout, new String[]{"objectClass"});
    }


    /**
     * Performs a base object search (i.e. just a search of the current entry, nothing below it).
     *
     * @param searchbase       the domain name (relative to initial context in ldap) to seach from.
     * @param filter           the non-null filter to use for the search
     * @param limit            the maximum number of results to return
     * @param timeout          the maximum time to wait before abandoning the search
     * @param returnAttributes an array of strings containing the names of attributes to search. (null = all, empty array = none)
     * @return list of search results ('SearchResult's); entries matching the search filter.
     */

    public NamingEnumeration searchBaseEntry(String searchbase, String filter, int limit,
                                             int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchBaseEntry(nameParser.parse(searchbase), filter, limit, timeout, returnAttributes);
/*
         NamingEnumeration result = null;

         if (returnAttributes != null  &&  returnAttributes.length == 0)
             returnAttributes = new String[] {"objectClass"};

         // specify search constraints to search subtree
         SearchControls constraints = new SearchControls();

         constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
         constraints.setCountLimit(limit);
         constraints.setTimeLimit(timeout);

         constraints.setReturningAttributes(returnAttributes);

         result = ctx.search(searchbase, filter, constraints);

         return result;
*/
    }


    /**
     * This method allows an object to be renamed, while also specifying
     * the exact fate of the old name.
     *
     * @param OldDN        the original name to be changed
     * @param NewDN        the new name
     * @param deleteOldRDN whether the rdn of the old name should be removed,
     *                     or retained as a second attribute value.
     */

    public void renameEntry(Name OldDN, Name NewDN, boolean deleteOldRDN)
            throws NamingException
    {
        String value = (deleteOldRDN) ? "true" : "false";
        try
        {
            ctx.addToEnvironment("java.naming.ldap.deleteRDN", value);

            renameEntry(OldDN, NewDN);

            ctx.addToEnvironment("java.naming.ldap.deleteRDN", "false");  // reset to default of 'false' afterwards.
        }
        catch (NamingException e)
        {
            ctx.addToEnvironment("java.naming.ldap.deleteRDN", "false");  // reset to default of 'false' afterwards.
            throw e;
        }
    }





// *********************************


    /**
     * <p>A wrapper for context.rename... changes the
     * distinguished name of an object.</p>
     * <p/>
     * <p>WARNING! this will fail for single valued manditory attributes.
     * since using 'deleteRDN = false' - use renameEntry(old, new, deleteOldRdn)
     * method instead - 30 May 2002.</p>
     *
     * @param oldDN current distinguished name of an object.
     * @param newDN the name it is to be changed to.
     */

    public void renameEntry(String oldDN, String newDN)
            throws NamingException
    {
        ctx.rename(oldDN, newDN);
    }


    /**
     * Copies an object to a new DN by the simple expedient of adding
     * an object with the new DN, and the attributes of the old object.
     *
     * @param fromDN the original object being copied
     * @param toDN   the new object being created
     */

    public void copyEntry(String fromDN, String toDN)
            throws NamingException
    {
        addEntry(toDN, read(fromDN));
    }


    /**
     * creates a new object (subcontext) with the given
     * dn and attributes.
     *
     * @param dn   the distinguished name of the new object
     * @param atts attributes for the new object
     */

    public void addEntry(String dn, Attributes atts)
            throws NamingException
    {
        ctx.createSubcontext(dn, atts);
    }

    /**
     * deletes a leaf entry (subcontext).  It is
     * an error to attempt to delete an entry which is not a leaf
     * entry, i.e. which has children.
     */

    public void deleteEntry(String dn)
            throws NamingException
    {
        ctx.destroySubcontext(dn);
    }


    /**
     * Reads all the attribute type and values for the given entry.
     *
     * @param dn the ldap string distinguished name of entry to be read
     * @return an 'Attributes' object containing a list of all Attribute
     *         objects.
     */

    public synchronized Attributes read(String dn)
            throws NamingException
    {
        return read(dn, null);
    }


    /**
     * Reads all the attribute type and values for the given entry.
     *
     * @param dn               the ldap string distinguished name of entry to be read
     * @param returnAttributes a list of specific attributes to return.
     * @return an 'Attributes' object containing a list of all Attribute
     *         objects.
     */

    public synchronized Attributes read(String dn, String[] returnAttributes)
            throws NamingException
    {
        return ctx.getAttributes(dn, returnAttributes);
    }

    /**
     * Modifies an object's attributes, either adding, replacing or
     * deleting the passed attributes.
     *
     * @param dn       distinguished name of object to modify
     * @param mod_type the modification type to be performed; one of
     *                 DirContext.REPLACE_ATTRIBUTE, DirContext.DELETE_ATTRIBUTE, or
     *                 DirContext.ADD_ATTRIBUTE.
     * @param attr     the new attributes to update the object with.
     */

    public void modifyAttributes(String dn, int mod_type, Attributes attr)
            throws NamingException
    {
        ctx.modifyAttributes(dn, mod_type, attr);
    }


    /**
     * Modifies an object's attributes, either adding, replacing or
     * deleting the passed attributes.
     *
     * @param dn      distinguished name of object to modify
     * @param modList a list of ModificationItems
     */

    public void modifyAttributes(String dn, ModificationItem[] modList)
            throws NamingException
    {
        ctx.modifyAttributes(dn, modList);
    }

    /**
     * Updates an object with a new set of attributes
     *
     * @param dn   distinguished name of object to update
     * @param atts the new attributes to update the object with.
     */

    public void updateEntry(String dn, Attributes atts)
            throws NamingException
    {
        modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, atts);
    }


    /**
     * deletes an attribute from an object
     *
     * @param dn distinguished name of object
     * @param a  the attribute to delete
     */

    public void deleteAttribute(String dn, Attribute a)
            throws NamingException

⌨️ 快捷键说明

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