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 9322535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:06:53+00:00 2026-06-19T04:06:53+00:00

I want to get attribute on my active directory with Java (Eclipse). I found

  • 0

I want to get attribute on my active directory with Java (Eclipse).

I found this code :

Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, 
        "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");

// Create the initial context
DirContext ctx = new InitialDirContext(env);

but I have start with this to know if there is a connection:

String ldapUrl = "ldap://"+serverAddress+":389";
//Prepare the environment with the username and password.
Hashtable env = new Hashtable();
DirContext ctx = null;
env.put(Context.SECURITY_PRINCIPAL, DOMAIN+username);
//env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);

ctx = LdapCtxFactory.getLdapCtxInstance(ldapUrl, env); // To test the connection

So how can I create an InitialDirContext ?
What should I put in env.put(Context.INITIAL_CONTEXT_FACTORY, "?????????") for that works ?

Thanks a lot.

  • 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-06-19T04:06:54+00:00Added an answer on June 19, 2026 at 4:06 am

    In the example you found, the connection is established when you do:

    // Create the initial context
    DirContext ctx = new InitialDirContext(env);
    

    For this to work, you need to have all the required environment properties set, like

    SECURITY_CREDENTIALS
    SECURITY_PRINCIPAL
    SECURITY_AUTHENTICATION
    PROVIDER_URL
    INITIAL_CONTEXT_FACTORY
    (possibly others depending on if you have encryption set in your Active Directory)
    

    The context factory is what Java is going to use to create that connection. If you don’t specify it, java will use the default which is com.sun.jndi.ldap.LdapCtxFactory, if I’m not mistaken.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml in string format. I want to get the attribute called
I want to set the LastPasswordSet attribute of a user in Microsoft Active Directory.
I'm trying to programatically create a new Active Directory user setting the sAMAccountName attribute
I'm inside a cfloop over a query. I want to get an attribute, but
I want to get all values of 'id' attribute of 'span' tag with html
I want to get all anchor elements on my page where the attribute rel
I am using xpath in java. I want to get all the attributes (name
What I want: get a xml from the AppData to use What I code
I am using JNDI to connect to the LDAP active directory, and I want
I want to get the details of some attribute(session,trade,student etc.), and i have their

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.