<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
    主站蜘蛛池模板: 精品国产免费人成网站| 在线免费视频一区| 九九久久精品国产免费看小说| 亚洲中文字幕一区精品自拍| 亚洲色WWW成人永久网址| 四虎免费久久影院| 性色av免费观看| 青青草原1769久久免费播放| 一级毛片试看60分钟免费播放| 亚洲日韩VA无码中文字幕| 久久久久久国产精品免费免费| 中文字幕无码亚洲欧洲日韩| 亚洲爆乳无码专区| 亚洲另类少妇17p| 免费人成年激情视频在线观看| 中国一级全黄的免费观看| 美女免费精品高清毛片在线视| 亚洲第一区在线观看| 日韩免费高清视频网站| 18禁免费无码无遮挡不卡网站| 亚洲精品无播放器在线播放| 久久精品国产亚洲av麻豆蜜芽 | 日韩免费观看的一级毛片| 免费A级毛片无码专区| 精品国产免费一区二区三区香蕉| 亚洲第一成人在线| 亚洲中文久久精品无码1| 亚洲国产精品yw在线观看| 亚洲国产一区二区a毛片| 亚洲AV无码成人精品区天堂| 国产精品亚洲片在线观看不卡| 毛片a级毛片免费播放100| 黄色网址免费观看| 一个人免费观看www视频在线| 波霸在线精品视频免费观看| 免费精品久久久久久中文字幕| 亚洲一级毛片视频| 亚洲最新在线视频| 国产亚洲精品影视在线| 久久久久亚洲AV无码去区首| 香港经典a毛片免费观看看|