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

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

      回復(fù)  更多評(píng)論
      
    MSN:envoydada@hotmail.com QQ:34935442
    主站蜘蛛池模板: 国产成人精品日本亚洲语音| 亚洲av无码国产精品色午夜字幕| 91嫩草亚洲精品| 美女视频黄的免费视频网页| 亚洲五月综合缴情在线观看| 中文在线观看永久免费| 亚洲免费观看视频| 野花香高清在线观看视频播放免费| 亚洲香蕉网久久综合影视| 中文字幕久精品免费视频| 亚洲国产精品久久久久久| 久久青草免费91线频观看不卡| 亚洲人成电影在线天堂| 国产精品成人观看视频免费| 亚洲一区二区三区无码国产| 免费毛片网站在线观看| 日本激情猛烈在线看免费观看| 久久精品国产亚洲7777| 国产精品偷伦视频观看免费| 亚洲精品午夜视频| 成人免费一区二区三区在线观看| 亚洲av日韩综合一区久热| 亚洲国产精品第一区二区三区| 国产成年无码久久久免费| 亚洲欧洲自拍拍偷综合| 免费观看理论片毛片| 国产精品免费在线播放| 亚洲色四在线视频观看| 成人毛片18女人毛片免费视频未| 国产亚洲视频在线| 国产亚洲福利精品一区| 无人在线直播免费观看| 免费福利在线观看| 亚洲成年轻人电影网站www| 黄瓜视频高清在线看免费下载| 老司机午夜性生免费福利| 图图资源网亚洲综合网站| 成年在线网站免费观看无广告| 国产亚洲精品美女久久久久| 久久久亚洲欧洲日产国码农村| 黄色成人网站免费无码av|