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.LdapExtClient Detail: |
public NamingEnumeration compare(DirContext dirContext,
String filter,
String entrydn) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
SearchControls searchcontrols = new SearchControls(0, 1, 0, new String[0], false, false);
return dirContext.search(entrydn, filter, searchcontrols);
}
Filter the data in the ldap directory |
public DirContext connect(String host,
String port,
String rootdn,
String username,
String password,
String connTimeOut,
boolean secure) throws NamingException {
DirContext dirContext;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // $NON-NLS-1$
StringBuffer sb = new StringBuffer(80);
if (secure) {
sb.append("ldaps://"); // $NON-NLS-1$
} else {
sb.append("ldap://"); // $NON-NLS-1$
}
sb.append(host);
if (port.length() >0){
sb.append(":"); // $NON-NLS-1$
sb.append(port);
}
sb.append("/"); // $NON-NLS-1$
sb.append(rootdn);
env.put(Context.PROVIDER_URL,sb.toString());
log.info("prov_url= " + env.get(Context.PROVIDER_URL)); // $NON-NLS-1$
if (connTimeOut.length() > 0) {
env.put("com.sun.jndi.ldap.connect.timeout", connTimeOut); // $NON-NLS-1$
}
env.put(Context.REFERRAL, "throw"); // $NON-NLS-1$
env.put("java.naming.batchsize", "0"); // $NON-NLS-1$ // $NON-NLS-2$
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.SECURITY_PRINCIPAL, username);
dirContext = new InitialDirContext(env);
return dirContext;
}
|
public DirContext createTest(DirContext dirContext,
Attributes attributes,
String string) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
return dirContext.createSubcontext(string, attributes);
}
Create the entry in the ldap directory for the given string |
public void deleteTest(DirContext dirContext,
String string) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
dirContext.destroySubcontext(string);
}
Delete the attribute from the ldap directory |
public void disconnect(DirContext dirContext) {
if (dirContext == null) {
log.info("Cannot disconnect null context");
return;
}
try {
dirContext.close();
} catch (NamingException e) {
log.warn("Ldap client disconnect - ", e);
}
}
disconnect from the server |
public void moddnOp(DirContext dirContext,
String ddn,
String newdn) throws NamingException {
log.debug("ddn and newDn= " + ddn + "@@@@" + newdn);
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
dirContext.rename(ddn, newdn);
}
ModDN the data in the ldap directory for the given search base
******************************************* |
public void modifyTest(DirContext dirContext,
ModificationItem[] mods,
String string) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
dirContext.modifyAttributes(string, mods);
}
Modify the attribute in the ldap directory for the given string |
public NamingEnumeration searchTest(DirContext dirContext,
String searchBase,
String searchFilter,
int scope,
long countlim,
int timelim,
String[] attrs,
boolean retobj,
boolean deref) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
if (log.isDebugEnabled()){
log.debug(
"searchBase=" + searchBase +
" scope=" + scope +
" countlim=" + countlim +
" timelim=" + timelim +
" attrs=" + JMeterUtils.unsplit(attrs,",") +
" retobj=" + retobj +
" deref=" + deref +
" filter=" + searchFilter
);
}
SearchControls searchcontrols = null;
searchcontrols = new SearchControls(scope, countlim, timelim, attrs, retobj, deref);
return dirContext.search(searchBase, searchFilter, searchcontrols);
}
Filter the data in the ldap directory for the given search base |