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

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

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

    隨筆-86  評(píng)論-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 閱讀(2296) 評(píng)論(1)  編輯  收藏 所屬分類: Java

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

      回復(fù)  更多評(píng)論
      
    MSN:envoydada@hotmail.com QQ:34935442
    主站蜘蛛池模板: 亚洲美女精品视频| 国产成人精品免费视频软件| 亚洲午夜久久久久久久久电影网| 亚洲人配人种jizz| 麻豆国产精品免费视频| 日本久久久久亚洲中字幕| 99精品视频在线视频免费观看| 亚洲av成人无码久久精品| a级大片免费观看| 久久夜色精品国产亚洲av| 免费一级做a爰片久久毛片潮| 亚洲av日韩片在线观看| 成年网在线观看免费观看网址| 狠狠综合久久综合88亚洲| 午夜免费福利视频| 青青草原精品国产亚洲av| 99免费观看视频| 亚洲精品午夜国产va久久| 韩国18福利视频免费观看| 亚洲偷自拍另类图片二区| 国产免费一区二区三区VR| 国产精品亚洲综合天堂夜夜| 中文字幕日韩亚洲| 久久久久久国产精品免费无码| 亚洲成人福利网站| 色播在线永久免费视频| 三上悠亚在线观看免费| 亚洲精品在线视频观看| 国产免费av片在线看| 黄色网址在线免费观看| 国产亚洲一区二区在线观看| 亚洲毛片免费视频| 亚洲色欲色欱wwW在线| 亚洲熟女一区二区三区| 国产精品69白浆在线观看免费| 视频一区在线免费观看| 亚洲高清中文字幕综合网| 免费h黄肉动漫在线观看| 久久免费动漫品精老司机| jiz zz在亚洲| 亚洲AV无码乱码在线观看富二代|