I'm using LdapCtxFactory to query some searches in a LDAP AD, but eclipse shows me a warning
Access restriction: The type 'LdapCtxFactory' is not API (restriction on required library '/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar')
But I can't find an equivalent in Java 8.
This is the code
@Override
public String executeQuery(String query, String attribute) { //(
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.SECURITY_PRINCIPAL, ldapUser);
props.put(Context.SECURITY_CREDENTIALS, ldapPassword);
String value = "";
try {
DirContext context = LdapCtxFactory.getLdapCtxInstance("ldap://" + adHost + '/', props);
SearchControls controls = new SearchControls();
controls.setSearchScope(SUBTREE_SCOPE);
NamingEnumeration<SearchResult> renum = context.search(activeDirectoryName, query, controls);
if (!renum.hasMore()) {
logger.error("Error while querying from ldap");
}
SearchResult result = renum.next();
value = result.getAttributes().get(attribute).get().toString();
} catch (Exception e) {
logger.error("Ha ocurrido un error al recuperar el atributo \"{}\" de AD", "", e);
}
return value;
}
I want to get rid of the HastTable too, but "getLdapCtxInstance" only admits HastTables