Link to home
Create AccountLog in
Active Directory

Active Directory

--

Questions

--

Followers

Top Experts

Avatar of Bobby Sandhu
Bobby Sandhu🇨🇦

how to connect to Active Directory from java to retrieve user information
I am trying this code and getting error message saying 'In order to perform this operation a successful bind must be completed on the connection., data 0, vece '

Code:
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;

Hashtable env= new Hashtable(11);
                        env.put(Context.SECURITY_AUTHENTICATION,"none");
                        env.put(Context.SECURITY_PRINCIPAL,"UID=username,OU=USERS,OU=NHQ,DC=GC,DC=CA");//
                        env.put(Context.SECURITY_CREDENTIALS, "password");//Password
                        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                        env.put(Context.PROVIDER_URL,"ldap://csc-scc.gc.ca");
                       
                        DirContext ctx = new InitialDirContext(env);
//                       See which server was used
                        System.out.println("ctx info: " +ctx.getEnvironment().get(Context.PROVIDER_URL));

                        //String[] sAttrIDs = new String[2];

                        Attributes attr = ctx.getAttributes("sAMAccountName=xxx-xxx\\username,OU=USERS,OU=NHQ,DC=GC,DC=CA");

                        System.out.println("Domain Name:"+ attr.get("name").get());

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Chris DentChris Dent🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Active Directory

Active Directory

--

Questions

--

Followers

Top Experts

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.