Example usage for javax.naming.directory Attribute remove

List of usage examples for javax.naming.directory Attribute remove

Introduction

In this page you can find the example usage for javax.naming.directory Attribute remove.

Prototype

Object remove(int ix);

Source Link

Document

Removes an attribute value from the ordered list of attribute values.

Usage

From source file:it.infn.ct.security.utilities.LDAPUtils.java

private static boolean toggleUserIDPGroup(String cn, boolean activate) {
    ResourceBundle rb = ResourceBundle.getBundle("ldap");
    String userDN = "cn=" + cn + "," + rb.getString("peopleRoot");
    String idpUser = rb.getString("usersGroup");

    DirContext ctx = null;/* w w  w . ja  v a2 s .co m*/
    try {
        ctx = getMainAuthContext();

        ModificationItem modAttrs[] = new ModificationItem[1];
        String attrsList[] = { "uniqueMember" };
        Attributes attributes = ctx.getAttributes(idpUser, attrsList);

        Attribute att = attributes.get("uniqueMember");
        if (activate) {
            att.add(userDN);
        } else {
            att.remove(userDN);
        }

        modAttrs[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, att);
        ctx.modifyAttributes(idpUser, modAttrs);
        return true;
    } catch (NamingException ex) {
        _log.error(ex);
    }

    return false;

}

From source file:org.springframework.ldap.core.DirContextAdapter.java

private void collectModifications(Attribute originalAttr, Attribute changedAttr, List modificationList)
        throws NamingException {

    Attribute originalClone = (Attribute) originalAttr.clone();
    Attribute addedValuesAttribute = new BasicAttribute(originalAttr.getID());

    for (int i = 0; i < changedAttr.size(); i++) {
        Object attributeValue = changedAttr.get(i);
        if (!originalClone.remove(attributeValue)) {
            addedValuesAttribute.add(attributeValue);
        }//from  w  w  w .jav a  2  s  .  c  o m
    }

    // We have now traversed and removed all values from the original that
    // were also present in the new values. The remaining values in the
    // original must be the ones that were removed.
    if (originalClone.size() > 0) {
        modificationList.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, originalClone));
    }

    if (addedValuesAttribute.size() > 0) {
        modificationList.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, addedValuesAttribute));
    }
}

From source file:org.springframework.ldap.core.DirContextAdapter.java

public void removeAttributeValue(String name, Object value) {
    if (!updateMode && value != null) {
        Attribute attr = originalAttrs.get(name);
        if (attr != null) {
            attr.remove(value);
            if (attr.size() == 0) {
                originalAttrs.remove(name);
            }/*from  w ww  . ja  v a  2s  . c om*/
        }
    } else if (updateMode) {
        Attribute attr = updatedAttrs.get(name);
        if (attr == null) {
            if (originalAttrs.get(name) != null) {
                attr = (Attribute) originalAttrs.get(name).clone();
                attr.remove(value);
                updatedAttrs.put(attr);
            }
        } else {
            attr.remove(value);
        }
    }
}