Search in sources :

Example 6 with LDAPEntry

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

the class JLDAPProviderImpl method searchImpl.

public Map<String, Map<String, List<String>>> searchImpl(final String baseDN, final SearchHelper searchHelper, final boolean onlyFirstValue) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    // make a copy so if it changes somewhere else we won't be affected.
    final SearchHelper effectiveSearchHelper = new SearchHelper(searchHelper);
    // replace a null dn with an empty string
    final String effectiveBaseDN = baseDN != null ? baseDN : "";
    final int ldapScope;
    switch(effectiveSearchHelper.getSearchScope()) {
        case ONE:
            ldapScope = LDAPConnection.SCOPE_ONE;
            break;
        case BASE:
            ldapScope = LDAPConnection.SCOPE_BASE;
            break;
        case SUBTREE:
            ldapScope = LDAPConnection.SCOPE_SUB;
            break;
        default:
            ldapScope = -1;
    }
    final Map<String, Map<String, List<String>>> returnMap = new LinkedHashMap<>();
    final LDAPSearchConstraints constraints = new LDAPSearchConstraints();
    constraints.setMaxResults(effectiveSearchHelper.getMaxResults());
    constraints.setTimeLimit(effectiveSearchHelper.getTimeLimit());
    final String[] returnAttributes = effectiveSearchHelper.getAttributes() == null ? null : effectiveSearchHelper.getAttributes().toArray(new String[effectiveSearchHelper.getAttributes().size()]);
    final LDAPSearchResults results;
    try {
        results = ldapConnection.search(effectiveBaseDN, ldapScope, effectiveSearchHelper.getFilter(), returnAttributes, false, constraints);
        while (results.hasMore()) {
            final LDAPEntry loopEntry = results.next();
            final String loopDN = loopEntry.getDN();
            final Map<String, List<String>> loopAttributes = new LinkedHashMap<>();
            final LDAPAttributeSet attrSet = loopEntry.getAttributeSet();
            for (final Object anAttrSet : attrSet) {
                final LDAPAttribute loopAttr = (LDAPAttribute) anAttrSet;
                if (onlyFirstValue) {
                    loopAttributes.put(loopAttr.getName(), Collections.singletonList(loopAttr.getStringValue()));
                } else {
                    loopAttributes.put(loopAttr.getName(), Arrays.asList(loopAttr.getStringValueArray()));
                }
            }
            returnMap.put(loopDN, loopAttributes);
        }
    } catch (LDAPException e) {
        if (!returnMap.isEmpty()) {
            return Collections.unmodifiableMap(returnMap);
        }
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
    return Collections.unmodifiableMap(returnMap);
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPSearchConstraints(com.novell.ldap.LDAPSearchConstraints) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) SearchHelper(com.novell.ldapchai.util.SearchHelper) LinkedHashMap(java.util.LinkedHashMap) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with LDAPEntry

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

the class JLDAPProviderImpl method readStringAttributes.

@ChaiProvider.LdapOperation
public Map<String, String> readStringAttributes(final String entryDN, final Set<String> attributes) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().readStringAttributes(entryDN, attributes);
    final Map<String, String> returnProps = new LinkedHashMap<>();
    try {
        final LDAPEntry entry = ldapConnection.read(entryDN, attributes.toArray(new String[attributes.size()]));
        for (final Object attr : entry.getAttributeSet()) {
            final LDAPAttribute lAttr = (LDAPAttribute) attr;
            returnProps.put(lAttr.getName(), lAttr.getStringValue());
        }
        return returnProps;
    } 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) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with LDAPEntry

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

the class JLDAPProviderImpl method readMultiByteAttribute.

@ChaiProvider.LdapOperation
public byte[][] readMultiByteAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().readMultiByteAttribute(entryDN, attribute);
    try {
        final LDAPEntry entry = ldapConnection.read(entryDN, new String[] { attribute });
        final LDAPAttribute ldapAttribute = entry.getAttribute(attribute);
        return ldapAttribute != null ? ldapAttribute.getByteValueArray() : new byte[0][0];
    } 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)

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