zoukankan      html  css  js  c++  java
  • 一个ldap的例子,虽然我知道在做什么,但是有结果了啊,嘻嘻

    package com;

    import javax.naming.Context;
    import javax.naming.NamingEnumeration;
    import javax.naming.directory.*;
    import java.util.Hashtable;
    import java.util.Enumeration;

    /**
     * Created by IntelliJ IDEA.
     * To change this template use File | Settings | File Templates.
     */
    public class JNDISearch {
        public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
        public static String MY_HOST = "ldap://localhost:389";
        public static String MY_SEARCHBASE = "o=NetscapeRoot";
        public static String MY_FILTER = "ou=Administrators";

        public static void main(String[] args) {
            try {
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
                env.put(Context.PROVIDER_URL, MY_HOST);

                DirContext ctx = new InitialDirContext(env);
                SearchControls constraints = new SearchControls();
                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

                NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER, constraints);
                while (results != null && results.hasMore()) {
                    SearchResult sr = (SearchResult) results.next();
                    String dn = sr.getName();
                    System.out.println("Distinguished Name is " + dn);
                    Attributes atts = sr.getAttributes();
                    for (NamingEnumeration ne = atts.getAll(); ne.hasMoreElements();) {
                        Attribute attr = (Attribute) ne.next();
                        String attrID = attr.getID();
                        System.out.println(attrID + ":");
                        for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) {
                            System.out.println(""t" + vals.nextElement());
                        }
                    }
                    System.out.println(""n");
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }































  • 相关阅读:
    MaskRCNN模型解读
    Centos7下WebLogic安装部署
    CentOS 7 安装 JAVA环境(JDK 1.8)
    Linux下如何查看tomcat是否安装、启动、文件路径、进程ID
    Nacos enable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    多线程系列(三)之线程池
    多线程系列(二)之Thread类
    多线程系列(一)之多线程基础
    Vue2/Vue3 自定义组件库
    EF Core使用单独的项目管理迁移
  • 原文地址:https://www.cnblogs.com/baoguo/p/1456639.html
Copyright © 2011-2022 走看看