Search in sources :

Example 6 with LDAPAttribute

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

the class JLDAPProviderImpl method writeStringAttributes.

@LdapOperation
@ModifyOperation
public final void writeStringAttributes(final String entryDN, final Map<String, String> attributeValues, final boolean overwrite) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().writeStringAttributes(entryDN, attributeValues, overwrite);
    final int modOption = overwrite ? LDAPModification.REPLACE : LDAPModification.ADD;
    final List<LDAPModification> modifications = new ArrayList<>();
    for (final Map.Entry<String, String> entry : attributeValues.entrySet()) {
        final String attrName = entry.getKey();
        final LDAPAttribute ldapAttr = new LDAPAttribute(attrName, entry.getValue());
        final LDAPModification mod = new LDAPModification(modOption, ldapAttr);
        modifications.add(mod);
    }
    final LDAPModification[] modificationArray = modifications.toArray(new LDAPModification[modifications.size()]);
    try {
        ldapConnection.modify(entryDN, modificationArray);
    } catch (LDAPException e) {
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPException(com.novell.ldap.LDAPException) LDAPModification(com.novell.ldap.LDAPModification) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with LDAPAttribute

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

the class JLDAPProviderImpl method compareStringAttribute.

@ChaiProvider.LdapOperation
public boolean compareStringAttribute(final String entryDN, final String attribute, final String value) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().compareStringAttribute(entryDN, attribute, value);
    final LDAPAttribute ldapAttr = new LDAPAttribute(attribute, value);
    try {
        return ldapConnection.compare(entryDN, ldapAttr);
    } catch (LDAPException e) {
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPException(com.novell.ldap.LDAPException)

Example 8 with LDAPAttribute

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

the class JLDAPProviderImpl method writeBinaryAttribute.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void writeBinaryAttribute(final String entryDN, final String attribute, final byte[][] values, final boolean overwrite, final ChaiRequestControl[] controls) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeBinaryAttribute(entryDN, attribute, values, overwrite);
    final LDAPAttribute ldapAttr = new LDAPAttribute(attribute);
    for (final byte[] value : values) {
        ldapAttr.addValue(value);
    }
    final LDAPModification mod = new LDAPModification(overwrite ? LDAPModification.REPLACE : LDAPModification.ADD, ldapAttr);
    try {
        if (controls != null && controls.length > 0) {
            final LDAPConstraints constraints = new LDAPConstraints();
            constraints.setControls(convertControls(controls));
            ldapConnection.modify(entryDN, mod, constraints);
        } else {
            ldapConnection.modify(entryDN, mod);
        }
    } catch (LDAPException e) {
        throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPException(com.novell.ldap.LDAPException) LDAPConstraints(com.novell.ldap.LDAPConstraints) LDAPModification(com.novell.ldap.LDAPModification)

Example 9 with LDAPAttribute

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

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

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