Ldap Client class is main class to create, modify, search and delete all the
LDAP functionality available.
Method from org.apache.jmeter.protocol.ldap.sampler.LdapClient Detail: |
public void connect(String host,
String port,
String rootdn,
String username,
String password) throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //$NON-NLS-1$
env.put(Context.PROVIDER_URL, "ldap://" + host + ":" + port + "/" + rootdn); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
env.put(Context.REFERRAL, "throw"); //$NON-NLS-1$
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.SECURITY_PRINCIPAL, username);
dirContext = new InitialDirContext(env);
}
|
public void createTest(BasicAttributes basicattributes,
String string) throws NamingException {
// DirContext dc = //TODO perhaps return this?
dirContext.createSubcontext(string, basicattributes);
}
Create the attribute in the ldap directory for the given string. |
public void deleteTest(String string) throws NamingException {
dirContext.destroySubcontext(string);
}
Delete the attribute from the ldap directory. |
public void disconnect() {
try {
if (dirContext != null) {
dirContext.close();
dirContext = null;
}
} catch (NamingException e) {
log.error("Ldap client - ", e);
}
}
Disconnect from the server. |
public void modifyTest(ModificationItem[] mods,
String string) throws NamingException {
dirContext.modifyAttributes(string, mods);
}
Modify the attribute in the ldap directory for the given string. |
public boolean searchTest(String searchBase,
String searchFilter) throws NamingException {
// System.out.println("Base="+searchBase+" Filter="+searchFilter);
SearchControls searchcontrols = new SearchControls(SearchControls.SUBTREE_SCOPE,
1L, // count limit
0, // time limit
null,// attributes (null = all)
false,// return object ?
false);// dereference links?
NamingEnumeration ne = dirContext.search(searchBase, searchFilter, searchcontrols);
// System.out.println("Loop "+ne.toString()+" "+ne.hasMore());
// while (ne.hasMore()){
// Object tmp = ne.next();
// System.out.println(tmp.getClass().getName());
// SearchResult sr = (SearchResult) tmp;
// Attributes at = sr.getAttributes();
// System.out.println(at.get("cn"));
// }
// System.out.println("Done "+ne.hasMore());
return ne.hasMore();
}
Filter the data in the ldap directory for the given search base. |