• AD域


    package com.zxwl.thst.common;

    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.NamingEnumeration;
    import javax.naming.NamingException;
    import javax.naming.directory.SearchControls;
    import javax.naming.directory.SearchResult;
    import javax.naming.ldap.InitialLdapContext;
    import javax.naming.ldap.LdapContext;
    public class Test
    {
    public static void main(String[] args) {
    Properties env = new Properties();
    String adminName = "administrator@2003.com";//username@domain
    String adminPassword = "hh123456";//password
    String ldapURL = "LDAP://10.10.2.153:389";//ip:port
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");//"none","simple","strong"
    env.put(Context.SECURITY_PRINCIPAL, adminName);
    env.put(Context.SECURITY_CREDENTIALS, adminPassword);
    env.put(Context.PROVIDER_URL, ldapURL);
    try {
    LdapContext ctx = new InitialLdapContext(env, null);
    SearchControls searchCtls = new SearchControls();
    searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    String searchFilter = "(&(objectCategory=person)(objectClass=user)(name=*))";
    String searchBase = "DC=2003,DC=com";
    String returnedAtts[] = {"memberOf"};
    searchCtls.setReturningAttributes(returnedAtts);
    NamingEnumeration<SearchResult> answer = ctx.search(searchBase, searchFilter,searchCtls);
    while (answer.hasMoreElements()) {
    SearchResult sr = (SearchResult) answer.next();
    System.out.println("<<<::[" + sr.getName()+"]::>>>>");
    }
    ctx.close();
    }catch (NamingException e) {
    e.printStackTrace();
    System.err.println("Problem searching directory: " + e);
    }
    }
    }

  • 相关阅读:
    linq——group by
    WebApi——json返回多了 k_BackingField
    Fiddler使用
    iis发布,部署
    项目梳理7——Nuget包管理
    CVS导出&&自定义Attribute的使用
    项目梳理6——使用WebApiTestClient为webapi添加测试
    项目梳理5——修改已生成.nuspec文件
    项目梳理4——WebApi项目,使用注释填充Description字段
    jQuery object and DOM Element
  • 原文地址:https://www.cnblogs.com/jcfxl/p/5948623.html
Copyright © 2020-2023  润新知