Search in sources :

Example 76 with InitialDirContext

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);
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 77 with InitialDirContext

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 78 with InitialDirContext

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();
}
Also used : InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 79 with InitialDirContext

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();
}
Also used : InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 80 with InitialDirContext

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();
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Aggregations

InitialDirContext (javax.naming.directory.InitialDirContext)131 DirContext (javax.naming.directory.DirContext)71 NamingException (javax.naming.NamingException)67 Hashtable (java.util.Hashtable)51 Attributes (javax.naming.directory.Attributes)34 Attribute (javax.naming.directory.Attribute)24 SearchResult (javax.naming.directory.SearchResult)22 SearchControls (javax.naming.directory.SearchControls)19 IOException (java.io.IOException)11 CommunicationException (javax.naming.CommunicationException)11 Test (org.junit.Test)11 Properties (java.util.Properties)10 BasicAttributes (javax.naming.directory.BasicAttributes)9 ArrayList (java.util.ArrayList)8 LoginException (javax.security.auth.login.LoginException)8 NameClassPair (javax.naming.NameClassPair)7 HashSet (java.util.HashSet)6 NamingEnumeration (javax.naming.NamingEnumeration)6 BasicAttribute (javax.naming.directory.BasicAttribute)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)5