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

📄 jndiops.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @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(Name 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(Name 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(Name 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(Name 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(Name dn, Attribute a)
            throws NamingException
    {
        BasicAttributes atts = new BasicAttributes();
        atts.put(a);
        modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, atts);
    }

    /**
     * deletes a set of attribute-s from an object
     *
     * @param dn distinguished name of object
     * @param a  the Attributes object containing the
     *           list of attribute-s to delete
     */


    public void deleteAttributes(Name dn, Attributes a)
            throws NamingException
    {
        modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, a);
    }

    /**
     * updates an Attribute with a new value set
     *
     * @param dn distinguished name of object
     * @param a  the attribute to modify
     */

    public void updateAttribute(Name dn, Attribute a)
            throws NamingException
    {
        BasicAttributes atts = new BasicAttributes();
        atts.put(a);
        modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, atts);
    }

    /**
     * updates a set of Attribute-s.
     *
     * @param dn distinguished name of object
     * @param a  an Attributes object containing the attribute-s to modify
     */

    public void updateAttributes(Name dn, Attributes a)
            throws NamingException
    {
        modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, a);
    }

    /**
     * Adds a new attribute to a particular dn.
     *
     * @param dn distinguished name of object
     * @param a  the attribute to modify
     */

    public void addAttribute(Name dn, Attribute a)
            throws NamingException
    {
        BasicAttributes atts = new BasicAttributes();
        atts.put(a);
        modifyAttributes(dn, DirContext.ADD_ATTRIBUTE, atts);
    }

    /**
     * Adds a set of attributes to a particular dn.
     *
     * @param dn distinguished name of object
     * @param a  the Attributes (set of attribute-s) to add
     */

    public void addAttributes(Name dn, Attributes a)
            throws NamingException
    {
        modifyAttributes(dn, DirContext.ADD_ATTRIBUTE, a);
    }


    /**
     * returns the next level of a directory tree, returning
     * a Enumeration of the results, *relative* to the SearchBase (i.e. not as
     * absolute DNs), along with their object classes if possible.
     *
     * @param Searchbase the node in the tree to expand
     * @return list of results (NameClassPair); the next layer of the tree...
     */

    public NamingEnumeration list(Name Searchbase)
            throws NamingException
    {
        //    Attempt to read the names of the next level of subentries along with their object
        //    classes.  Failing that, try to just read their names.

// just do a real 'list', without object classes...
//        return rawSearchOneLevel(Searchbase, "(objectclass=*)", 0, 0, new String[]{"1.1"});

// a JXplorer 'list' returns object classes as well, so we can play silly buggers with GUI icons
        return rawSearchOneLevel(Searchbase, "(objectclass=*)", 0, 0, new String[]{"objectclass"});
    }


    /**
     * Performs a one-level directory search (i.e. a search of immediate children), returning
     * object classes if possible, otherwise just the names.
     *
     * @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 searchOneLevel(String searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return searchOneLevel(searchbase, filter, limit, timeout, new String[]{"1.1"});
    }

    /**
     * Performs a one-level directory search (i.e. a search of immediate children)
     *
     * @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 searchOneLevel(String searchbase, String filter, int limit,
                                            int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchOneLevel(nameParser.parse(searchbase), filter, limit, timeout, returnAttributes);
    }


    /**
     * Performs a one-level directory search (i.e. a search of immediate children), returning
     * object classes if possible, otherwise just the names.
     *
     * @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 searchOneLevel(Name searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return rawSearchOneLevel(searchbase, filter, limit, timeout, new String[]{"1.1"});
    }

    /**
     * Performs a one-level directory search (i.e. a search of immediate children)
     *
     * @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 searchOneLevel(Name searchbase, String filter, int limit,
                                            int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchOneLevel(searchbase, filter, limit, timeout, returnAttributes);
    }

    /**
     * Method that calls the actual search on the jndi context.
     *
     * @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
     * @throws NamingException
     */
    protected NamingEnumeration rawSearchOneLevel(Name searchbase, String filter, int limit,
                                                  int timeout, String[] returnAttributes) throws NamingException
    {
        /* specify search constraints to search one level */
        SearchControls constraints = new SearchControls();

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

        constraints.setReturningAttributes(returnAttributes);

//        NamingEnumeration results = ctx.search(searchbase, filter, null);
        NamingEnumeration results = ctx.search(searchbase, filter, constraints);

        return results;

    }

    /**
     * Performs a directory sub tree search (i.e. of the next level and all subsequent levels below),
     * returning 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. WARNING - these may be RELATIVE to the seachbase.
     */
    public NamingEnumeration searchSubTree(Name searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return searchSubTree(searchbase, filter, limit, timeout, new String[]{"1.1"});
    }

    /**
     * Performs a directory sub tree search (i.e. of the next level and all subsequent levels below),
     * returning 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. WARNING - these may be RELATIVE to the seachbase.
     */
    public NamingEnumeration searchSubTree(String searchbase, String filter, int limit, int timeout)
            throws NamingException
    {
        return searchSubTree((searchbase), filter, limit, timeout, new String[]{"1.1"});
    }

    /**
     * Performs a directory sub tree search (i.e. of the next level and all subsequent levels below).
     *
     * @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. WARNING - these may be RELATIVE to the seachbase.
     */

    public NamingEnumeration searchSubTree(String searchbase, String filter, int limit,
                                           int timeout, String[] returnAttributes)
            throws NamingException
    {
        return rawSearchSubTree(nameParser.parse(searchbase), filter, limit, timeout, returnAttributes);

//         SearchControls constraints = setSubTreeSearchControls(returnAttributes, limit, timeout);

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

    /**
     * Performs a directory sub tree search (i.e. of the next level and all subsequent levels below).
     *
     * @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. WARNING - these may be RELATIVE to the seachbase.
     */

⌨️ 快捷键说明

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