如何将Java连接到Active Directory
我使用的是Weblogic,Ejb3.0。 Java 1.6
我需要通过Java代码访问Active Directory。 我读了几种方法(Kerberos,LDAP)
任何人都可以建议我这样做的舒适方式? 我在哪里可以找到一些完整的代码示例,
谢谢,雷。
这是一个简单的代码,用于在W2K3上对JNDI进行身份validation并进行LDAP搜索:
class TestAD { static DirContext ldapContext; public static void main (String[] args) throws NamingException { try { System.out.println("Début du test Active Directory"); Hashtable ldapEnv = new Hashtable(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //ldapEnv.put(Context.PROVIDER_URL, "ldap://societe.fr:389"); ldapEnv.put(Context.PROVIDER_URL, "ldap://dom.fr:389"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); //ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=administrateur,cn=users,dc=societe,dc=fr"); ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=jean paul blanc,ou=MonOu,dc=dom,dc=fr"); ldapEnv.put(Context.SECURITY_CREDENTIALS, "pwd"); //ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl"); //ldapEnv.put(Context.SECURITY_PROTOCOL, "simple"); ldapContext = new InitialDirContext(ldapEnv); // Create the search controls SearchControls searchCtls = new SearchControls(); //Specify the attributes to return String returnedAtts[]={"sn","givenName", "samAccountName"}; searchCtls.setReturningAttributes(returnedAtts); //Specify the search scope searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); //specify the LDAP search filter String searchFilter = "(&(objectClass=user))"; //Specify the Base for the search String searchBase = "dc=dom,dc=fr"; //initialize counter to total the results int totalResults = 0; // Search for objects using the filter NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchCtls); //Loop through the search results while (answer.hasMoreElements()) { SearchResult sr = (SearchResult)answer.next(); totalResults++; System.out.println(">>>" + sr.getName()); Attributes attrs = sr.getAttributes(); System.out.println(">>>>>>" + attrs.get("samAccountName")); } System.out.println("Total results: " + totalResults); ldapContext.close(); } catch (Exception e) { System.out.println(" Search error: " + e); e.printStackTrace(); System.exit(-1); } } }
- 将Ldap用户与使用Java的组关联
- 用户解锁后,Windows机器上的Kerberos缓存票证无法重新生成
- 在尝试使用unboundid LDAP SDK更改scala中的密码时,如何解决“WILL_NOT_PERFORM”MS AD回复?
- 我可以从LDAP更改自己的Active Directory密码(没有管理帐户)
- 密码的SPNEGO身份validation问题
- 校验和失败:Kerberos / Spring / Active Directory(2008)
- 无法从Java获得与AD的连接
- 通过Java执行ADS相关的Powershell命令在使用2种不同方式时不会产生2种不同的错误
- 在Java中使用LDAP的最简单方法(Eclipse)