/* 1. Extract common name CN from LDAP server, distinguished name uid, password userpassword, email address mail
* Using the Netscape LDAP server as a test environment, log on to the LDAP server using simple authentication.
* 2. Using the name ' admin ' password is ' 1 ', the entire program uses the JNDI standard interface in SDK1.4.1.
* 3. To support Domino database development, assume that the IP address of the user at logon is already recorded in the field UID and separated by ', '
* The program will eventually print a string that includes all user names, passwords, and IP addresses.
* 4. The use of regular expressions is introduced in the process of separating user names and IP addresses.
*/
package mm;
public class jndisearch{
public static String Initctx = "Com.sun.jndi.ldap.LdapCtxFactory"; Driven
public static String My_host = "ldap://localhost:389"; Host address and Port
public static String my_searchbase = "o=airius.com"; Base Point Entrance
public static String My_filter = "(mail=west)"; Filter conditions
public static String mgr_dn= "Uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoot"; User name
public static String mgr_pw= "1"; Password
public static String my_attrs[] = {/* "cn", "UserPassword", "Mail", */"cn"};
StringBuffer res = new StringBuffer (); Object used to enter the name, IP address
public static String temp = new String ();
Public String Search () throws exception{
StringBuffer res = new StringBuffer ();
try{
Establish a connection
Hashtable env = new Hashtable ();
Env.put (CONTEXT.INITIAL_CONTEXT_FACTORY,INITCTX);
Env.put (Context.provider_url,my_host);
Env.put (Context.security_authentication, "simple"); Use simple authentication to authenticate users
Env.put (CONTEXT.SECURITY_PRINCIPAL,MGR_DN);
Env.put (CONTEXT.SECURITY_CREDENTIALS,MGR_PW);
DirContext CTX = new InitialDirContext (env);
Set query scope and start query
Searchcontrols constraints = new Searchcontrols ();
Constraints.setsearchscope (Searchcontrols.subtree_scope);
Namingenumeration results = Ctx.search (my_searchbase,my_filter,constraints);
Splitstring sp = new splitstring ();
System.out.println ("A Total" +sp.splitstring (res.tostring ()). length+ "a return"); Print display results, calculate returned array values
Return sp.splitstring (Res.tostring ());
return res.tostring ();
}
///////////////////////////////////////////////////////////////////////////////////////////
Use regular expressions to sort extracted strings///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.