//Create the initial directory context System.out.println("here is 111"); LdapContext ctx = new InitialLdapContext(env,null); System.out.println("here is 222");
//Create the search controls SearchControls searchCtls = new SearchControls();
//Specify the search scope searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter String searchFilter = "(cn=HAL*)";
//Specify the Base for the search String searchBase = "dc=centos5,dc=com";
//String searchBase = "o=centos5.com";
//initialize counter to total the group members int totalResults = 0;
//Specify the attributes to return String returnedAtts[]={"member"}; System.out.println("here is 3"); searchCtls.setReturningAttributes(returnedAtts); System.out.println("here is 4"); //Search for objects using the filter NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
System.out.println("here is 5");
//Loop through the search results /*while (answer.hasMoreElements()) { SearchResult sr = (SearchResult)answer.next();
System.out.println(">>>" + sr.getName());
//Print out the members
Attributes attrs = sr.getAttributes(); if (attrs != null) {
try { for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) { Attribute attr = (Attribute)ae.next(); System.out.println("Attribute: " + attr.getID()); for (NamingEnumeration e = attr.getAll();e.hasMore();totalResults++) {
Last edited by msi_333 on Sun Jun 29, 2008 11:48 pm, edited 1 time in total.
Put the code tags for code
msi_333
Question subject: Re: problems to connect to active directory
Posted: Mon Jun 30, 2008 12:11 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
hi ramy, i want to knew what is active directory ?? And . Do you have any exception from this code
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
ramy6_1
Question subject: Re: problems to connect to active directory
Posted: Mon Jun 30, 2008 9:35 am
Joined: Sun Jun 01, 2008 12:15 pm Posts: 4 Has thanked: 0 time Have thanks: 0 time
hi msi
thanks for your interest
i work on windows 2000 server ,it has active directory ,
i get this result when i run this code
here is 1 here is 2 here is 111 Problem searching directory: javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 57, v893
so the problem that it can't connect to active directory .
i wish you can help me since it really very critical point in my work,we have to make many applications and all is stopped because of this problem.
i wait you
mileloader
Question subject: Re: problems to connect to active directory
Posted: Mon Jun 30, 2008 8:50 pm
Joined: Sun May 25, 2008 5:34 pm Posts: 95 Has thanked: 2 time Have thanks: 1 time
I think your problem in this line :
Code:
LdapContext ctx = new InitialLdapContext(env,null);
there is a problem in connection request controls, why you put null
I think in line env.put(Context.SECURITY_PRINCIPAL,"dc=development,dc=local");//User
you can write in "dc=development,dc=local" into something like accountname@com.???.com
abooysen3
Question subject: Re: problems to connect to active directory
Posted: Wed Feb 25, 2009 1:59 pm
Joined: Wed Feb 25, 2009 1:48 pm Posts: 3 Has thanked: 0 time Have thanks: 0 time
Hi
here is a basic Ldap (Active Directory Authentication) package beans;
try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL,"LDAP://xx.xxxxx.xx:389"); //replace with your server URL/IP //only DIGEST-MD5 works with our Windows Active Directory env.put(Context.SECURITY_AUTHENTICATION,"DIGEST-MD5"); //No other SALS worked with me env.put(Context.SECURITY_PRINCIPAL,userName); // specify the username ONLY to let Microsoft Happy env.put(Context.SECURITY_CREDENTIALS, passWord); //the password DirContext ctx = new InitialDirContext(env); //Create the search controls SearchControls searchCtls = new SearchControls();
//Specify the attributes to return String returnedAtts[]={"cn","DisplayName"}; searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctx.close(); } catch(NamingException ne) { System.out.println("Error authenticating user:"); System.out.println(ne.getMessage()); return; } //if no exception, the user is already authenticated. System.out.println("OK, successfully authenticating user"); } }
You can then custimatize this according to your requirements. Remember //only DIGEST-MD5 works with our Windows Active Directory always works with windows
msi_333
Question subject: Re: problems to connect to active directory
Posted: Wed Feb 25, 2009 2:47 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
thank you "abooysen3 "
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
abooysen3
Question subject: Re: problems to connect to active directory
Posted: Thu Feb 26, 2009 6:09 am
Joined: Wed Feb 25, 2009 1:48 pm Posts: 3 Has thanked: 0 time Have thanks: 0 time