Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:47:13+00:00 2026-05-30T03:47:13+00:00

I tried to read the User Names which are in the Active Directory, but

  • 0

I tried to read the User Names which are in the Active Directory, but I am getting an error. The error is:
Exception in thread “main” javax.naming.AuthenticationException: [LDAP: error code 49 – 80090308: LdapErr: DSID-0C0903AA, comment: AcceptSecurityContext error, data 525, v1772]

However, my code is:

package client;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.directory.*;
    import javax.naming.ldap.*;
    import javax.naming.*;
    import java.util.Hashtable;
    import java.util.Enumeration;
public class AD {
    public AD() {
        super();
    }


            public static void main(String[] args) throws NamingException {
                    Hashtable envVars = new Hashtable();
                    envVars.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                    envVars.put(Context.PROVIDER_URL, "ldap://" + "IP:Port");
                    envVars.put(Context.SECURITY_AUTHENTICATION, "simple");
                    envVars.put(Context.SECURITY_PRINCIPAL, "username");
                    envVars.put(Context.SECURITY_CREDENTIALS, "password");


                    DirContext myContext = new InitialDirContext(envVars);
                    try{

                    SearchControls searchCtrls = new SearchControls();
                    searchCtrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                    String[] attributes = { "cn", "telephoneNumber", "sn", "userPrincipalName","memberOf","name" };
                    searchCtrls.setReturningAttributes(attributes);


                    String filter = "(objectClass=organizationalPerson)";
                    NamingEnumeration values = myContext.search("CN=Users,DC=bma.gov.bh,DC=gov,DC=bh",filter, searchCtrls);
                    while (values.hasMoreElements())
                    {
                           SearchResult result = (SearchResult) values.next();
                            Attributes attribs = result.getAttributes();


                            if (null != attribs)
                            {
                                    for (NamingEnumeration ae = attribs.getAll(); ae.hasMoreElements();)
                                    {
                                            Attribute atr = (Attribute) ae.next();
                                            String attributeID = atr.getID();
                                            for (
                                                    Enumeration vals = atr.getAll(); 
                                                    vals.hasMoreElements(); 
                                                    System.out.println(attributeID +": " +vals.nextElement()) );
                                    }
                            }
                    }


                    myContext.close();


                    }

                    catch(Exception e)
                    {
                            //e
                    }
            }



}

The problem is starting from this line:

DirContext myContext = new InitialDirContext(envVars);

Can you please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:47:16+00:00Added an answer on May 30, 2026 at 3:47 am

    The error code you got 80090308 can be found in winerror.h – and it says

    The token supplied to the function is invalid

    Most probably this is caused by the fact that Active Directory expects the password to be UTF-8 encoded byte array, and the Java string is not that.

    Try changing your code as this:

    envVars.put(Context.SECURITY_CREDENTIALS, "password".getBytes("UTF8"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am practicing making a web app which tries to read the user's twitter
I'm still entangled in error handling problems. After having read and tried lots of
I've read numerous articles on this topic and tried implementing a few, but I
I tried to read a file in a view like this: def foo(request): f
I am wondering what would happen if I tried to read files in Java
HI all, When I tried to read the record of all peoples from the
I just downloaded the Oxygene free command line compiler, and tried to read the
I stumbled over a curious bug, I think: I tried to read 512 as
after read this article i tried generate EF model by System.Diagnostics.Process: Process myProcess =
I tried to implement this example to write and read data from internal storage,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.