Active Directory

Hii JavatiesDo i need to have password of administartor for getting list of users from Active Directory in Java?
[126 byte] By [help_eachothera] at [2007-11-26 12:53:59]
# 1
I would say yes. I mess around with AD at work every day and when I try to open it without an admin password, I can only view my account. I can't see anyone elses.
Leditiona at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanx for ur reply.I am able to get list of users from Domino LDAP , but now i want 2 get the list of users in Active directory.Can u suggest wht changes i have to make in my earlier code ?
help_eachothera at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...
# 3
Why exactly is this a Java question again?
CeciNEstPasUnProgrammeura at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...
# 4

> Thanx for ur reply.

> I am able to get list of users from Domino LDAP ,

> but now i want 2 get the list of users in Active

> directory.

> Can u suggest wht changes i have to make in my

> earlier code ?

Changes to what earlier code? I see no code.

Or should you not just be using a sys user credentials?

Ted.

ted_trippina at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...
# 5

I am using th following code for getting the list of users ->

public class LDAP {

private String tCtx="com.sun.jndi.ldap.LdapCtxFactory";

//private String tAuth="simple";

private String tAuth="simple";

private String org="C=IN";

private String tURL="ldap://server01:389";

private Properties env = null;

public static final int AUTH_SUCCESS= 1;

/** A constant representing that authentication failed. */

public static final int AUTH_FAILURE= 2;

/** A constant representing that user ID is invalid. */

public static final int AUTH_INVALIDUSER= 3;

/** A constant representing that error is not one of authentication failure or invalid user. */

public static final int AUTH_OTHER= 4;

// constructor

private String fullName;

private String commonName;

private String abbrevatedName;

public LDAP() {

try{

ResourceBundle rbDomino = ResourceBundle.getBundle("Domino", Locale.getDefault());

Enumeration enumDomino = rbDomino.getKeys();

while(enumDomino.hasMoreElements()){

String strKey = (String)enumDomino.nextElement();

if(strKey != null && strKey.equals("ip-address")){

tURL = rbDomino.getString(strKey);

}

else if(strKey != null && strKey.equals("org")){

org = rbDomino.getString(strKey);

}

}

}catch(MissingResourceException e){

System.out.println("Property file not defined.");

}

env = new Properties();

env.put(Context.INITIAL_CONTEXT_FACTORY, tCtx);

env.put(Context.PROVIDER_URL, tURL);

env.put(Context.SECURITY_AUTHENTICATION, tAuth);

}

public ArrayList getAllUsers(){

String userName = null;System.out.println(" Getting allUsers ");

NamingEnumeration userInfo = null;

SearchResult sr = null;

String filter = null;

SearchControls ctls = new SearchControls();

ArrayList grouplist = new ArrayList();

grouplist.add("");

filter = "uid=*";

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

try {

DirContext authenticationctx = new InitialDirContext(env);

userInfo = authenticationctx.search(org, filter, ctls);

while(userInfo.hasMoreElements()){

sr = (SearchResult) userInfo.next();

userName = sr.getName();

if(userName.indexOf("//C") > 0)

userName = userName.substring(userName.indexOf("//C")+2);

userName = userName.substring(userName.indexOf("/C")+1);

grouplist.add(userName);

}

return grouplist;

}catch (NoSuchElementException nse) {

System.err.println("no matching user found.");

return null;

}catch (NamingException ne) {

System.err.println("naming exception"+ne);

return null;

}catch(Exception e){

e.printStackTrace();

return null;

}

}

}

What changes i need to do in this code , so that it works with AD ?

help_eachothera at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...
# 6
Well, for one, you haven't supplied the username and password, eg.env.put(javax.naming.Context.SECURITY_PRINCIPAL, userDn);env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);Ted.
ted_trippina at 2007-7-7 16:45:18 > top of Java-index,Java Essentials,Java Programming...