Toya G
asked on
Ignoring Disabled Group Members in LDAP Java Query
I have a java ldap query where I pull all users that exist in a group. However, I now need to filter out disabled accounts. How do I modify my search to exclude disabled users?
Below is my current java ldap query.
private LdapContext getTM1users(MbElement parser) throws FileNotFoundException, SQLException, IOException, MbException, NamingException
{
LdapContext ctx = null;
MbElement start = null;
Attributes attrs = null;
NamingEnumeration answer = null;
String group = null;
String location = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CO NTEXT_FACT ORY, "Factory");
env.put(Context.SECURITY_A UTHENTICAT ION, "Simple");
env.put(Context.SECURITY_P RINCIPAL, "UserID");
env.put(Context.SECURITY_C REDENTIALS , "Password");
env.put(Context.PROVIDER_U RL, "ldapURL");
ctx = new InitialLdapContext(env, null);
SearchControls constraints = new SearchControls();
constraints.setSearchScope (SearchCon trols.SUBT REE_SCOPE) ;
String[] attrIDs = {"sAMAccountName"};
constraints.setReturningAt tributes(a ttrIDs);
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put("Agent_Comm", "Agent_Comm");
ht.put("Elec_Finance", "Elec_Finance");
ht.put("Freight", "Freight");
ht.put("Vids", "Vids");
Set<String> keys = ht.keySet();
for(String key : keys)
{
group = ht.get(key);
location = key;
answer = ctx.search("DC=ads,DC=abc, DC=com", "memberOf=CN=" + group + ",OU=ADM,OU=ABC,DC=ads,DC= abc,DC=com ", constraints);
while (answer.hasMore())
{
attrs = ((SearchResult) answer.next()).getAttribut es();
start = parser.createElementAsFirs tChild(MbE lement.TYP E_NAME, "user", null);
start.createElementAsFirst Child(MbEl ement.TYPE _NAME_VALU E, "userid",attrs.get("sAMAcc ountName") .toString( ).trim());
start.createElementAsFirst Child(MbEl ement.TYPE _NAME_VALU E, "location", location);
}
}
return ctx;
}
Below is my current java ldap query.
private LdapContext getTM1users(MbElement parser) throws FileNotFoundException, SQLException, IOException, MbException, NamingException
{
LdapContext ctx = null;
MbElement start = null;
Attributes attrs = null;
NamingEnumeration answer = null;
String group = null;
String location = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CO
env.put(Context.SECURITY_A
env.put(Context.SECURITY_P
env.put(Context.SECURITY_C
env.put(Context.PROVIDER_U
ctx = new InitialLdapContext(env, null);
SearchControls constraints = new SearchControls();
constraints.setSearchScope
String[] attrIDs = {"sAMAccountName"};
constraints.setReturningAt
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put("Agent_Comm", "Agent_Comm");
ht.put("Elec_Finance", "Elec_Finance");
ht.put("Freight", "Freight");
ht.put("Vids", "Vids");
Set<String> keys = ht.keySet();
for(String key : keys)
{
group = ht.get(key);
location = key;
answer = ctx.search("DC=ads,DC=abc,
while (answer.hasMore())
{
attrs = ((SearchResult) answer.next()).getAttribut
start = parser.createElementAsFirs
start.createElementAsFirst
start.createElementAsFirst
}
}
return ctx;
}
ASKER
Thanks Ravi. However, that solution did not pull back any members, although members exist.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Please replace your search criteria code with below
answer = ctx.search("DC=ads,DC=abc,
Thanks,
Ravi Katkuri