use of javax.naming.directory.InitialDirContext in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerImpl method validateInitialDirContext.
private void validateInitialDirContext(Class<? extends SocketFactory> sslSocketFactoryOverrideClass, final String providerUrl, final String searchUsername, final String searchPassword) {
Hashtable<String, Object> env = createInitialDirContextEnvironment(providerUrl);
setupSearchContext(env, searchUsername, searchPassword);
InitialDirContext ctx = null;
try {
ctx = createInitialDirContext(env, sslSocketFactoryOverrideClass);
} catch (NamingException e) {
LOGGER.error("Failed to establish connectivity to the ldap server for '{}'", providerUrl, e);
throw new IllegalConfigurationException("Failed to establish connectivity to the ldap server.", e);
} finally {
closeSafely(ctx);
}
}
use of javax.naming.directory.InitialDirContext in project nifi by apache.
the class QueryDNS method initializeContext.
// This was separated from main code to ease the creation of test units injecting fake JNDI data
// back into the processor.
protected void initializeContext(Hashtable<String, String> env) throws NamingException {
this.ictx = new InitialDirContext(env);
this.initialized = new AtomicBoolean(false);
initialized.set(true);
}
use of javax.naming.directory.InitialDirContext in project Lucee by lucee.
the class LDAPClient method modifydn.
/**
* modifies distinguished name attribute for LDAP entries on LDAP server
* @param dn
* @param attributes
* @throws NamingException
*/
public void modifydn(String dn, String attributes) throws NamingException {
DirContext ctx = new InitialDirContext(env);
ctx.rename(dn, attributes);
ctx.close();
}
use of javax.naming.directory.InitialDirContext in project Lucee by lucee.
the class LDAPClient method add.
/**
* adds LDAP entries to LDAP server
* @param dn
* @param attributes
* @param delimiter
* @throws NamingException
* @throws PageException
*/
public void add(String dn, String attributes, String delimiter, String seperator) throws NamingException, PageException {
DirContext ctx = new InitialDirContext(env);
ctx.createSubcontext(dn, toAttributes(attributes, delimiter, seperator));
ctx.close();
}
use of javax.naming.directory.InitialDirContext in project Lucee by lucee.
the class LDAPClient method modify.
public void modify(String dn, int modifytype, String strAttributes, String delimiter, String separator) throws NamingException, PageException {
DirContext context = new InitialDirContext(env);
String[] strArrAttributes = toStringAttributes(strAttributes, delimiter);
int count = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String[] attributesValues = getAttributesValues(strArrAttributes[i], separator);
if (attributesValues == null)
count++;
else
count += attributesValues.length;
}
ModificationItem[] modItems = new ModificationItem[count];
BasicAttribute basicAttr = null;
int k = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String attribute = strArrAttributes[i];
String type = getAttrValueType(attribute);
String[] values = getAttributesValues(attribute, separator);
if (modifytype == DirContext.REPLACE_ATTRIBUTE) {
if (values == null)
basicAttr = new BasicAttribute(type);
else
basicAttr = new BasicAttribute(type, values[0]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
if (values != null && values.length > 1) {
for (int j = 1; j < values.length; j++) {
basicAttr = new BasicAttribute(type, values[j]);
modItems[k] = new ModificationItem(DirContext.ADD_ATTRIBUTE, basicAttr);
k++;
}
}
} else {
for (int j = 0; j < values.length; j++) {
if (type != null || modifytype == DirContext.ADD_ATTRIBUTE)
basicAttr = new BasicAttribute(type, values[j]);
else
basicAttr = new BasicAttribute(values[j]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
}
}
}
context.modifyAttributes(dn, modItems);
context.close();
}
Aggregations