Search in sources :

Example 1 with LDAPModification

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

the class JLDAPProviderImpl method deleteStringAttributeValue.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void deleteStringAttributeValue(final String entryDN, final String attribute, final String value) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().deleteStringAttributeValue(entryDN, attribute, value);
    final LDAPAttribute ldapAttr = new LDAPAttribute(attribute, value);
    final LDAPModification mod = new LDAPModification(LDAPModification.DELETE, ldapAttr);
    try {
        ldapConnection.modify(entryDN, mod);
    } 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)

Example 2 with LDAPModification

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

the class JLDAPProviderImpl method replaceStringAttribute.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void replaceStringAttribute(final String entryDN, final String attributeName, final String oldValue, final String newValue) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().replaceStringAttribute(entryDN, attributeName, oldValue, newValue);
    final LDAPModification[] modifications;
    modifications = new LDAPModification[2];
    modifications[0] = new LDAPModification(LDAPModification.DELETE, new LDAPAttribute(attributeName, oldValue));
    modifications[1] = new LDAPModification(LDAPModification.ADD, new LDAPAttribute(attributeName, newValue));
    try {
        ldapConnection.modify(entryDN, modifications);
    } 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)

Example 3 with LDAPModification

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

the class JLDAPProviderImpl method writeStringAttribute.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void writeStringAttribute(final String entryDN, final String attribute, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttribute(entryDN, attribute, values, overwrite);
    final LDAPAttribute ldapAttr = new LDAPAttribute(attribute, values.toArray(new String[values.size()]));
    final LDAPModification mod = new LDAPModification(overwrite ? LDAPModification.REPLACE : LDAPModification.ADD, ldapAttr);
    try {
        ldapConnection.modify(entryDN, mod);
    } 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)

Example 4 with LDAPModification

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

the class JLDAPProviderImpl method replaceBinaryAttribute.

@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void replaceBinaryAttribute(final String entryDN, final String attribute, final byte[] oldValue, final byte[] newValue) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().replaceBinaryAttribute(entryDN, attribute, oldValue, newValue);
    final LDAPModification[] modifications;
    modifications = new LDAPModification[2];
    modifications[0] = new LDAPModification(LDAPModification.DELETE, new LDAPAttribute(attribute, oldValue));
    modifications[1] = new LDAPModification(LDAPModification.ADD, new LDAPAttribute(attribute, newValue));
    try {
        ldapConnection.modify(entryDN, modifications);
    } 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)

Example 5 with LDAPModification

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

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)6 LDAPException (com.novell.ldap.LDAPException)6 LDAPModification (com.novell.ldap.LDAPModification)6 LDAPConstraints (com.novell.ldap.LDAPConstraints)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1