Search in sources :

Example 11 with LDAPAttribute

use of com.novell.ldap.LDAPAttribute 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)

Example 12 with LDAPAttribute

use of com.novell.ldap.LDAPAttribute 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 13 with LDAPAttribute

use of com.novell.ldap.LDAPAttribute 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 14 with LDAPAttribute

use of com.novell.ldap.LDAPAttribute 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

LDAPAttribute (com.novell.ldap.LDAPAttribute)14 LDAPException (com.novell.ldap.LDAPException)12 LDAPModification (com.novell.ldap.LDAPModification)6 LDAPEntry (com.novell.ldap.LDAPEntry)5 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)4 LinkedHashMap (java.util.LinkedHashMap)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Iterator (java.util.Iterator)2 List (java.util.List)2 LDAPConstraints (com.novell.ldap.LDAPConstraints)1 LDAPSearchConstraints (com.novell.ldap.LDAPSearchConstraints)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 SearchHelper (com.novell.ldapchai.util.SearchHelper)1 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 IOException (java.io.IOException)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1