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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:50:40+00:00 2026-05-27T17:50:40+00:00

I am using Weblogic, Ejb3.0. Java 1.6 I need to access Active Directory via

  • 0

I am using Weblogic, Ejb3.0. Java 1.6

I need to access Active Directory via Java code.
I read about several ways (Kerberos, LDAP)

Anyone could advice me on comfortable way of doing so? where could I have some full code examples,

thanks,
ray.

  • 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-27T17:50:41+00:00Added an answer on May 27, 2026 at 5:50 pm

    Here is a simple code that authenticate and make an LDAP search usin JNDI on a W2K3 :

    class TestAD
    {
      static DirContext ldapContext;
      public static void main (String[] args) throws NamingException
      {
        try
        {
          System.out.println("Début du test Active Directory");
    
          Hashtable<String, String> ldapEnv = new Hashtable<String, String>(11);
          ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          //ldapEnv.put(Context.PROVIDER_URL,  "ldap://societe.fr:389");
          ldapEnv.put(Context.PROVIDER_URL,  "ldap://dom.fr:389");
          ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
          //ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=administrateur,cn=users,dc=societe,dc=fr");
          ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=jean paul blanc,ou=MonOu,dc=dom,dc=fr");
          ldapEnv.put(Context.SECURITY_CREDENTIALS, "pwd");
          //ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
          //ldapEnv.put(Context.SECURITY_PROTOCOL, "simple");
          ldapContext = new InitialDirContext(ldapEnv);
    
          // Create the search controls         
          SearchControls searchCtls = new SearchControls();
    
          //Specify the attributes to return
          String returnedAtts[]={"sn","givenName", "samAccountName"};
          searchCtls.setReturningAttributes(returnedAtts);
    
          //Specify the search scope
          searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    
          //specify the LDAP search filter
          String searchFilter = "(&(objectClass=user))";
    
          //Specify the Base for the search
          String searchBase = "dc=dom,dc=fr";
          //initialize counter to total the results
          int totalResults = 0;
    
          // Search for objects using the filter
          NamingEnumeration<SearchResult> answer = ldapContext.search(searchBase, searchFilter, searchCtls);
    
          //Loop through the search results
          while (answer.hasMoreElements())
          {
            SearchResult sr = (SearchResult)answer.next();
    
            totalResults++;
    
            System.out.println(">>>" + sr.getName());
            Attributes attrs = sr.getAttributes();
            System.out.println(">>>>>>" + attrs.get("samAccountName"));
          }
    
          System.out.println("Total results: " + totalResults);
          ldapContext.close();
        }
        catch (Exception e)
        {
          System.out.println(" Search error: " + e);
          e.printStackTrace();
          System.exit(-1);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Weblogic 11, ejb3.0 I have code which is doing lookup to
We are using Seam 2.2.0 Java 1.6.14 Weblogic 10.3.1.0 (named 11g Doh!) I have
I am using Weblogic 11g, EJB3.0. I am struggling for weeks with this problem.
Using Ejb3.0, Weblogic 11g, JDBC I am invoking a method which is running remotely
Under Weblogic 10, I am using Hibernate to store data into several tables with
I am using maven weblogic plugin 10.3.4. I have read the goal list of
I am using Weblogic 11g, EJB3.0. I am trying to do simple look up
I am using Weblogic 116, Ejb3.0 , quartz-all 1.8.5. I have issues with quartz
I am using EJB3.0, Weblogic 11g I am trying to do simple lookup from
I am using Weblogic for deploying my Java EE applications. I am using JSP

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.