Search in sources :

Example 1 with LDAPEntry

use of com.novell.ldap.LDAPEntry in project ldapchai by ldapchai.

the class JLDAPProviderImpl method createEntry.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void createEntry(final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes) throws ChaiOperationException {
    activityPreCheck();
    getInputValidator().createEntry(entryDN, baseObjectClasses, stringAttributes);
    final LDAPAttributeSet ldapAttributeSet = new LDAPAttributeSet();
    ldapAttributeSet.add(new LDAPAttribute(ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClasses.toArray(new String[baseObjectClasses.size()])));
    if (stringAttributes != null) {
        for (final Map.Entry<String, String> entry : stringAttributes.entrySet()) {
            final String attrName = entry.getKey();
            ldapAttributeSet.add(new LDAPAttribute(attrName, entry.getValue()));
        }
    }
    final LDAPEntry newEntry = new LDAPEntry(entryDN, ldapAttributeSet);
    try {
        ldapConnection.add(newEntry);
    } catch (LDAPException e) {
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPException(com.novell.ldap.LDAPException) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with LDAPEntry

use of com.novell.ldap.LDAPEntry in project neo4j-apoc-procedures by neo4j-contrib.

the class LoadLdapTest method testLoadLDAP.

@Test
public void testLoadLDAP() throws Exception {
    Map<String, Object> connParms = new HashMap<>();
    connParms.put("ldapHost", "ldap.forumsys.com");
    connParms.put("ldapPort", 389l);
    connParms.put("loginDN", "cn=read-only-admin,dc=example,dc=com");
    connParms.put("loginPW", "password");
    LoadLdap.LDAPManager mgr = new LoadLdap.LDAPManager(LoadLdap.getConnectionMap(connParms));
    Map<String, Object> searchParms = new HashMap<>();
    searchParms.put("searchBase", "dc=example,dc=com");
    searchParms.put("searchScope", "SCOPE_ONE");
    searchParms.put("searchFilter", "(&(objectClass=*)(uid=training))");
    ArrayList<String> ats = new ArrayList<>();
    ats.add("uid");
    searchParms.put("attributes", ats);
    LDAPSearchResults results = mgr.doSearch(searchParms);
    LDAPEntry le = results.next();
    assertEquals("uid=training,dc=example,dc=com", le.getDN());
    assertEquals("training", le.getAttribute("uid").getStringValue());
}
Also used : LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with LDAPEntry

use of com.novell.ldap.LDAPEntry in project janrufmonitor by tbrandt77.

the class LdapContactsProxy method getContacts.

public synchronized ICallerList getContacts(String category) throws LdapContactsException {
    ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
    String query = "(objectclass=*)";
    if (category != null) {
        String ldapAttrib = LdapMappingManager.getInstance().getLdapAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
        if (ldapAttrib != null && ldapAttrib.trim().length() > 0) {
            query = "(" + ldapAttrib + "=" + category + ")";
        }
    }
    LDAPConnection lc = new LDAPConnection();
    try {
        lc.connect(getServer(), getPort());
        lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF-8"));
        LDAPSearchConstraints cons = lc.getSearchConstraints();
        cons.setMaxResults(getMaxResults());
        String baseDN = this.getBaseDN();
        String[] bases = null;
        if (baseDN.indexOf("|") > 0) {
            bases = baseDN.split("\\|");
        } else {
            bases = new String[] { baseDN };
        }
        for (int i = 0; i < bases.length; i++) {
            LDAPSearchResults searchResults = lc.search(bases[i], getScope(), query, // return all attributes
            null, // return attrs and values
            false, cons);
            ICaller c = null;
            while (searchResults.hasMore()) {
                LDAPEntry nextEntry = null;
                try {
                    nextEntry = searchResults.next();
                } catch (LDAPException e) {
                    if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
                        break;
                    else
                        continue;
                }
                c = LdapMappingManager.getInstance().mapToJamCaller(nextEntry);
                if (c != null) {
                    cl.add(c);
                }
            }
        }
        // disconnect from the server
        lc.disconnect();
        LdapMappingManager.invalidate();
    } catch (LDAPException e) {
        this.m_logger.log(Level.SEVERE, e.toString(), e);
        throw new LdapContactsException(e.toString(), e);
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.SEVERE, e.toString(), e);
    }
    if (this.m_dbh != null) {
        try {
            this.m_dbh.deleteAll();
            ICaller c = null;
            for (int i = 0, j = cl.size(); i < j; i++) {
                c = cl.get(i);
                if (c instanceof IMultiPhoneCaller) {
                    List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                    IPhonenumber pn = null;
                    for (int k = 0; k < phones.size(); k++) {
                        pn = (IPhonenumber) phones.get(k);
                        this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                    }
                } else {
                    IPhonenumber pn = c.getPhoneNumber();
                    this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                }
            }
        } catch (SQLException e) {
            throw new LdapContactsException(e.getMessage(), e);
        }
    } else {
        this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
    }
    return cl;
}
Also used : SQLException(java.sql.SQLException) LDAPSearchConstraints(com.novell.ldap.LDAPSearchConstraints) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPConnection(com.novell.ldap.LDAPConnection) ICaller(de.janrufmonitor.framework.ICaller) LDAPEntry(com.novell.ldap.LDAPEntry) ICallerList(de.janrufmonitor.framework.ICallerList) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 4 with LDAPEntry

use of com.novell.ldap.LDAPEntry in project janrufmonitor by tbrandt77.

the class LdapContactsProxy method identifyByUUID.

private ICaller identifyByUUID(String uuid) throws LdapContactsException {
    LDAPConnection lc = new LDAPConnection();
    try {
        lc.connect(getServer(), getPort());
        lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF8"));
        lc.read(uuid);
        // return attrs and values
        LDAPEntry entry = lc.read(uuid);
        if (entry != null) {
            ICaller c = LdapMappingManager.getInstance().mapToJamCaller(entry);
            if (c != null) {
                return c;
            }
        }
    } catch (LDAPException e) {
        throw new LdapContactsException(e.toString(), e);
    } catch (UnsupportedEncodingException e) {
        throw new LdapContactsException(e.toString(), e);
    } finally {
        LdapMappingManager.invalidate();
        try {
            lc.disconnect();
        } catch (LDAPException e) {
            throw new LdapContactsException(e.toString(), e);
        }
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPException(com.novell.ldap.LDAPException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPConnection(com.novell.ldap.LDAPConnection)

Example 5 with LDAPEntry

use of com.novell.ldap.LDAPEntry in project ldapchai by ldapchai.

the class JLDAPProviderImpl method readMultiStringAttribute.

@ChaiProvider.LdapOperation
public Set<String> readMultiStringAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().readMultiStringAttribute(entryDN, attribute);
    try {
        final LDAPEntry entry = ldapConnection.read(entryDN, new String[] { attribute });
        final LDAPAttribute ldapAttribute = entry.getAttribute(attribute);
        if (ldapAttribute == null) {
            return Collections.emptySet();
        } else {
            return new HashSet<String>(Arrays.asList(ldapAttribute.getStringValueArray()));
        }
    } catch (LDAPException e) {
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPException(com.novell.ldap.LDAPException) HashSet(java.util.HashSet)

Aggregations

LDAPEntry (com.novell.ldap.LDAPEntry)8 LDAPException (com.novell.ldap.LDAPException)7 LDAPAttribute (com.novell.ldap.LDAPAttribute)5 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)3 LinkedHashMap (java.util.LinkedHashMap)3 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)2 LDAPConnection (com.novell.ldap.LDAPConnection)2 LDAPSearchConstraints (com.novell.ldap.LDAPSearchConstraints)2 ICaller (de.janrufmonitor.framework.ICaller)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 SearchHelper (com.novell.ldapchai.util.SearchHelper)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1