Search in sources :

Example 1 with LDAPAttributeSet

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

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

the class LdapMappingManager method mapAttributes.

private IAttributeMap mapAttributes(LDAPEntry entry) {
    IAttributeMap attributes = getRuntime().getCallerFactory().createAttributeMap();
    LDAPAttributeSet attributeSet = entry.getAttributeSet();
    Iterator allAttributes = attributeSet.iterator();
    while (allAttributes.hasNext()) {
        LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
        if (m_attributeMappings.values().contains(attribute.getName())) {
            String value = attribute.getStringValue();
            if (m_logger.isLoggable(Level.INFO)) {
                m_logger.info("Adding LDAP attribute: " + attribute.getName() + ", value: " + value);
            }
            if (!m_inversAttributeMappings.getProperty(attribute.getName()).equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
                attributes.add(getRuntime().getCallerFactory().createAttribute(m_inversAttributeMappings.getProperty(attribute.getName()), value));
            } else {
                try {
                    addImage(attributes, attribute.getByteValue(), entry);
                } catch (IOException e) {
                    m_logger.log(Level.SEVERE, e.toString(), e);
                }
            }
        }
    }
    return attributes;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) Iterator(java.util.Iterator) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IOException(java.io.IOException)

Example 3 with LDAPAttributeSet

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

the class LdapMappingManager method mapPhones.

private List mapPhones(LDAPEntry entry, IAttributeMap attributes) {
    List phones = new ArrayList();
    LDAPAttributeSet attributeSet = entry.getAttributeSet();
    Iterator allAttributes = attributeSet.iterator();
    while (allAttributes.hasNext()) {
        LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
        if (m_phonenumberMappings.keySet().contains(attribute.getName())) {
            Enumeration allValues = attribute.getStringValues();
            if (allValues != null) {
                String value = null;
                while (allValues.hasMoreElements()) {
                    value = (String) allValues.nextElement();
                    if (!Base64.isLDIFSafe(value)) {
                        value = attribute.getStringValue();
                    }
                    if (m_logger.isLoggable(Level.INFO)) {
                        m_logger.info("Adding LDAP attribute: " + attribute.getName() + ", value: " + value);
                    }
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("LdapMappingManager raw number: " + value);
                    }
                    IPhonenumber pn = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(value);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("LdapMappingManager identified number: " + pn);
                    }
                    if (pn != null) {
                        phones.add(pn);
                        attributes.add(getNumberTypeAttribute(attribute.getName(), pn));
                    }
                }
            }
        }
    }
    return phones;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Enumeration(java.util.Enumeration) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 4 with LDAPAttributeSet

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

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)4 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)4 LDAPEntry (com.novell.ldap.LDAPEntry)2 LDAPException (com.novell.ldap.LDAPException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 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