<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-86  評論-33  文章-0  trackbacks-0

     

    import java.util.Properties;
    import javax.naming.*;
    import javax.naming.ldap.*;
    import javax.naming.directory.*;
    public class Client {
    public static void main (String[] args) {
        Properties env 
    = new Properties();
        String adminName 
    = "usish\\derek";
        String adminPassword 
    = "dada";
        String ldapURL 
    = "LDAP://192.168.40.42:389";
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
    "com.sun.jndi.ldap.LdapCtxFactory");
    //set security credentials, note using simple cleartext authentication
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, adminName);
        env.put(Context.SECURITY_CREDENTIALS, adminPassword);
    //connect to my domain controller
        env.put(Context.PROVIDER_URL, ldapURL);

        
    try {
    //Create the initial directory context
            LdapContext ctx = new InitialLdapContext(env, null);

    //Create the search controls
            SearchControls searchCtls = new SearchControls();

    //Specify the search scope
            searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    //specify the LDAP search filter
            String searchFilter = "(&(objectCategory=person)(objectClass=user)(name=004*))";

    //Specify the Base for the search
            String searchBase = "OU=USISH,DC=usish,DC=com,DC=cn";
    //initialize counter to total the group members
            int totalResults = 0;
    //Specify the attributes to return
            String returnedAtts[] = {"memberOf"};
            searchCtls.setReturningAttributes(returnedAtts);

    //Search for objects using the filter
            NamingEnumeration answer = ctx.search(searchBase, searchFilter,
                                                  searchCtls);
    //Loop through the search results
            while (answer.hasMoreElements()) {
                SearchResult sr 
    = (SearchResult) answer.next();
                System.out.println(
    ">>>" + sr.getName());
                
    //Print out the groups
                Attributes attrs = sr.getAttributes();
                
    if (attrs != null) {
                    
    try {
                        
    for (NamingEnumeration ae = attrs.getAll(); ae.hasMore(); ) {
                            Attribute attr 
    = (Attribute) ae.next();
                            System.out.println(
    "AttributeID: " + attr.getID());
                            
    for (NamingEnumeration e = attr.getAll(); e.hasMore();
                                    totalResults
    ++) {
                                System.out.println(
    "Attributes:"+e.next());                            
                            }
                        }
                    } 
    catch (NamingException e) {
                        e.printStackTrace();
                        System.err.println(
    "Problem listing membership: " + e);
                    }
                }
            }
            System.out.println(
    "Total groups: " + totalResults);
            ctx.close();
        }
    catch (NamingException e) {
            e.printStackTrace();
            System.err.println(
    "Problem searching directory: " + e);
        }
     }
    }
    posted on 2007-05-09 15:12 Derek.Guo 閱讀(2294) 評論(1)  編輯  收藏 所屬分類: Java

    評論:
    # re: JAVA訪問LDAP[未登錄] 2008-09-28 13:22 | ice
    我在運上面的代碼出現(xiàn)了 cuold not find the main class.Program will exit! 問題怎么解決啊 ,能幫幫我嗎,我是第一遇到這個問題

      回復(fù)  更多評論
      
    MSN:envoydada@hotmail.com QQ:34935442
    主站蜘蛛池模板: 亚洲风情亚Aⅴ在线发布| 亚洲精品网站在线观看你懂的| 日韩亚洲不卡在线视频中文字幕在线观看| 久久九九全国免费| 亚洲午夜久久久久久噜噜噜| 久香草视频在线观看免费| 伊人婷婷综合缴情亚洲五月| 中文字幕不卡免费视频| 久久久久亚洲精品无码网址| 国产精品永久免费| 亚洲国产精品一区二区第一页| 精品亚洲永久免费精品| 亚洲AV电影院在线观看| 免费黄色网址网站| 亚洲欧洲日产国码久在线| 国产免费黄色大片| 久久国产精品免费| 亚洲系列国产精品制服丝袜第| 国产大片91精品免费观看不卡| 亚洲日韩中文字幕一区| 免费人成在线观看网站品爱网日本| 免费一区二区三区在线视频| 亚洲综合在线另类色区奇米| 91精品国产免费网站| 亚洲日韩中文字幕一区| 亚洲人成无码网站久久99热国产| 国产免费一区二区视频| 亚洲乱码中文论理电影| 免费人成网站在线播放| 久久久精品午夜免费不卡| 亚洲性猛交xx乱| 免费国产成人高清在线观看麻豆| 国产精品偷伦视频免费观看了| 久久久久亚洲av无码专区 | 久久精品私人影院免费看| 亚洲春色在线观看| 国产男女性潮高清免费网站| 国产精品免费看久久久香蕉| 亚洲另类春色国产精品| 免费人妻无码不卡中文字幕18禁| 91香蕉国产线在线观看免费|