javax.naming.AuthenticationException

Hi i am trying to retieve user attributes from Windows Active Directory using the following code:

import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
 
 
public class searchgc      {
      public static void main (String[] args)      {
                        Hashtable envGC = new Hashtable();
             
            String adminName = "CN=Administrator,CN=Users,DC=ANTIPODES,DC=COM";
            String adminPassword = "XXXXXXX";
 
            String urlGC = "ldap://mydc.antipodes.com:389";
            
 
            envGC.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
            
 
            //set security credentials, note using simple cleartext authentication
            envGC.put(Context.SECURITY_AUTHENTICATION,"simple");
            envGC.put(Context.SECURITY_PRINCIPAL,adminName);
            envGC.put(Context.SECURITY_CREDENTIALS,adminPassword);
 
             
            //connect to both a GC and  DC
            envGC.put(Context.PROVIDER_URL,urlGC);
                        
            //We need to chase referrals when retrieving attributes from the DC
            //as the object may be in a different domain
            envDC.put(Context.REFERRAL,"follow");
                  
            try {
 
                  //Create the initial directory context for both DC and GC
                  LdapContext ctxGC = new InitialLdapContext(envGC,null);
                                    
            
                  //Now perform a search against the GC
                  //Create the search controls             
                  SearchControls searchCtls = new SearchControls();
            
                  //Specify the attributes to return
                  String returnedAtts[]={"sn"};
                  searchCtls.setReturningAttributes(returnedAtts);
            
                  //Specify the search scope
                  searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
 
                  //specify the LDAP search filter
                  String searchFilter = "(&(objectClass=user)(mail=*)(|(givenName=Albert)(givenName=Isaac)))";
 
                  //Specify the Base for the search
                  //an empty dn for all objects from all domains in the forest
                  String searchBase = "";
 
                  //initialize counter to total the results
                  int totalResults = 0;
 
 
                  //Search for objects in the GC using the filter
                  NamingEnumeration answer = ctxGC.search(searchBase, searchFilter, searchCtls);
 
                  //Loop through the search results
                  while (answer.hasMoreElements()) {
                        SearchResult sr = (SearchResult)answer.next();
 
                        totalResults++;
 
                        System.out.println(">>>" + sr.getName());
 
                        // Print out some of the attributes, catch the exception if the attributes have no values
                        Attributes attrs = sr.getAttributes();
                        if (attrs != null) {
                              try {
                                    System.out.println("   name(GC): " + attrs.get("givenName").get() + " " + attrs.get("sn").get());
                                    System.out.println("   mail(GC): " + attrs.get("mail").get());
                              }
                              catch (NullPointerException e)      {
                                    System.err.println("Problem listing attributes from Global Catalog: " + e);
                              }
                        
                        }
                         
                  }
 
                   System.out.println("Total results: " + totalResults);
                  ctxGC.close();
                  
            }
            catch (NamingException e) {
                  System.err.println("Problem searching directory: " + e);
            }
 
      }      
}

GIVING ME THE FOLLOWING ERROR:

Problem searching directory: javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 525, v893]

Please help me with the problem it is really urgent
thank u
ravi
dhulipalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dhulipalaAuthor Commented:
I AM SORRY I TYPED THE TITLE WRONG IT IS  javax.naming.AuthenticationException
0
objectsCommented:
check the authentication details are correct
0
dhulipalaAuthor Commented:


I am sorry i didnt understand your answer exactly ... what are authentication details...

thanks
-ravi
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

objectsCommented:
that the username and password you are supplying are correct
0
dhulipalaAuthor Commented:


Actually i have question regarding that... I am tyring to access my attributes from my university server whose URL is of type    .xx.xx.edu
I am a user of the server. I am giving the following details :

String urlGC = "ldap://xxx.xx.xx.edu:389";

String adminName = "CN=my username,CN=Users,DC=xxx,DC=xx,DC=xx,DC=edu";
 String adminPassword = "my password";

Am i doing in the right way or not??

Please help,
ravi
0
objectsCommented:
Looks correct (assuming the details you are supplying are correct)

Some background at:
http://java.sun.com/products/jndi/tutorial/ldap/security/ldap.html
0
kupra1Commented:
replace ur adminName:
>>>CN=my username,CN=Users,DC=xxx,DC=xx,DC=xx,DC=edu

by
adminName=Administrator@mydc.antipodes.com
0
kupra1Commented:
I meant use
adminName=myusername@xxx.xx.xx.edu
0
dhulipalaAuthor Commented:
Hi ... What should be the search filterlike ... with
String searchFilter = "(&(objectClass=user)(|(givenName=shashank)(givenName=nagula)))";

I think it is giving this exception:
Problem searching directory: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100198, problem 2001 (NO_OBJEC
T), data 0, best match of:
        ''
]; remaining name ''


Please help
ravi
0
kupra1Commented:
So, you are not getting the authentication exception anymore.
What adminName are you using?
0
dhulipalaAuthor Commented:
Since i am testing this on my university server(xxx.xx.xx.edu). I am using my account login name as the adminName.
whis is like c5733s5dhulipalar
thanks
ravi.
0
kupra1Commented:
kool... so your authentication problem has been resolved. Now, you are getting this NameNotFoundException because your searchBase is empty.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dhulipalaAuthor Commented:
Hi good thing is i am not getting any exceptions after giving searchBase ... at the same time i am not getting any result..
None of the System.out.println are printing out after this part:

while (answer.hasMoreElements()) {

                        System.out.println("Ravi:");
                        SearchResult sr = (SearchResult)answer.next();
 
                        totalResults++;
 
                        System.out.println(">>>" + sr.getName());
 
                        // Print out some of the attributes, catch the exception if the attributes have no values
                        Attributes attrs = sr.getAttributes();
                        if (attrs != null) {
0
kupra1Commented:
This is because "answer" is empty. It has got no elements. To verify this, change the "while" to "if" and then add an else block.
if(answer.hasMoreElements()) {
       System.out.println("Answer is not empty");
       //
} else {
       System.out.println("Answer is empty");
}
0
dhulipalaAuthor Commented:

Hi your earlier suggestions in eliminating exceptions and stuff helped a lot in solving the problem ... the code worked

thanks again
ravi.
0
kupra1Commented:
Thanks a lot. I think that you should now look at your other similar open question too.
Thanks for the points again.

Prabhakar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.