Active Directory
--
Questions
--
Followers
Top Experts
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_A UTHENTICAT ION,"none" );
env.put(Context.SECURITY_P RINCIPAL," UID=userna me,OU=USER S,OU=NHQ,D C=GC,DC=CA ");//
env.put(Context.SECURITY_C REDENTIALS , "password");//Password
env.put(Context.INITIAL_CO NTEXT_FACT ORY, "com.sun.jndi.ldap.LdapCtx Factory");
env.put(Context.PROVIDER_U RL,"ldap:/ /csc-scc.g c.ca");
DirContext ctx = new InitialDirContext(env);
// See which server was used
System.out.println("ctx info: " +ctx.getEnvironment().get( Context.PR OVIDER_URL ));
//String[] sAttrIDs = new String[2];
Attributes attr = ctx.getAttributes("sAMAcco untName=xx x-xxx\\use rname,OU=U SERS,OU=NH Q,DC=GC,DC =CA");
System.out.println("Domain Name:"+ attr.get("name").get());
Code:
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
Hashtable env= new Hashtable(11);
env.put(Context.SECURITY_A
env.put(Context.SECURITY_P
env.put(Context.SECURITY_C
env.put(Context.INITIAL_CO
env.put(Context.PROVIDER_U
DirContext ctx = new InitialDirContext(env);
// See which server was used
System.out.println("ctx info: " +ctx.getEnvironment().get(
//String[] sAttrIDs = new String[2];
Attributes attr = ctx.getAttributes("sAMAcco
System.out.println("Domain
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
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
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.