Among the solutions we use at work, non-web services such as MFPs (printers) and WPF apps were changed to authenticate via LDAP. M365 and LDAP sync roughly every five minutes, so they stay near real time.
LDAP is just another communication protocol like HTTP, so there is not much to explain. Below is the sample we guided vendors to apply, plus how we load-tested it with JMeter.

LDAPSample.java

package ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
public class LDAPSample {
public static void main(String[] args) {
// LDAP server details
String ldapUrl = "ldap://LDAP-IP:LDAP-PORT";
String ldapUsername = "example@naver.com";
String ldapPassword = "enter passwrod";
// LDAP search parameters
String searchBase = "DC=example,DC=ad";
String searchFilter = "(userParameters="+ldapUsername.split("@")[0]+")";
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
try {
// Create the initial context
DirContext context = new InitialDirContext(env);
// Perform LDAP search
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = context.search(searchBase, searchFilter, searchControls);
// Iterate through the search results
SearchResult result = results.next();
Attributes attrs = result.getAttributes();
System.out.println("DN: " + result.getNameInNamespace());
// Print attributes
NamingEnumeration attributes = attrs.getAll();
while (attributes.hasMore()) {
Attribute attribute = attributes.next();
System.out.println(attribute.getID() + ": " + attribute.get());
}
// Close the context
context.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

JMeter load test

Before applying the source, I ran a JMeter load test and checked the summary report and results tree.

I also kept a test setup handy for operations: when someone says LDAP login fails, ask for their ID and password and try it yourself.
Leave a Reply