List of usage examples for javax.naming.directory DirContext REMOVE_ATTRIBUTE
int REMOVE_ATTRIBUTE
To view the source code for javax.naming.directory DirContext REMOVE_ATTRIBUTE.
Click Source Link
From source file:org.springframework.ldap.core.DirContextAdapter.java
/** * Collect all modifications for the changed attribute. If no changes have * been made, return immediately. If modifications have been made, and the * original size as well as the updated size of the attribute is 1, replace * the attribute. If the size of the updated attribute is 0, remove the * attribute. Otherwise, the attribute is a multi-value attribute; if it's * an ordered one it should be replaced in its entirety to preserve the new * ordering, if not all modifications to the original value (removals and * additions) will be collected individually. * /*from w w w.j a v a 2 s .c om*/ * @param changedAttr the value of the changed attribute. * @param modificationList the list in which to add the modifications. * @throws NamingException if thrown by called Attribute methods. */ private void collectModifications(Attribute changedAttr, List modificationList) throws NamingException { Attribute currentAttribute = originalAttrs.get(changedAttr.getID()); if (changedAttr.equals(currentAttribute)) { // No changes return; } else if (currentAttribute != null && currentAttribute.size() == 1 && changedAttr.size() == 1) { // Replace single-vale attribute. modificationList.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr)); } else if (changedAttr.size() == 0 && currentAttribute != null) { // Attribute has been removed. modificationList.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, changedAttr)); } else if ((currentAttribute == null || currentAttribute.size() == 0) && changedAttr.size() > 0) { // Attribute has been added. modificationList.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, changedAttr)); } else if (changedAttr.size() > 0 && changedAttr.isOrdered()) { // This is a multivalue attribute and it is ordered - the original // value should be replaced with the new values so that the ordering // is preserved. modificationList.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr)); } else if (changedAttr.size() > 0) { // Change of multivalue Attribute. Collect additions and removals // individually. List myModifications = new LinkedList(); collectModifications(currentAttribute, changedAttr, myModifications); if (myModifications.isEmpty()) { // This means that the attributes are not equal, but the // actual values are the same - thus the order must have // changed. This should result in a REPLACE_ATTRIBUTE operation. myModifications.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr)); } modificationList.addAll(myModifications); } }
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); }//w ww.j a v a 2s .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.swordess.ldap.util.ModUtils.java
public static ModificationItem remove(String id) { return new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(id)); }
From source file:org.swordess.ldap.util.ModUtils.java
public static ModificationItem remove(String id, Object value) { return create(DirContext.REMOVE_ATTRIBUTE, id, value, null); }
From source file:org.swordess.ldap.util.ModUtils.java
public static <T> ModificationItem remove(String id, Object value, Evaluator<T> evaluator) { return create(DirContext.REMOVE_ATTRIBUTE, id, value, evaluator); }
From source file:org.swordess.ldap.util.ModUtils.java
public static ModificationItem remove(String id, Object[] values) { return create(DirContext.REMOVE_ATTRIBUTE, id, values, null); }
From source file:org.swordess.ldap.util.ModUtils.java
public static <T> ModificationItem remove(String id, Object[] values, Evaluator<T> evaluator) { return create(DirContext.REMOVE_ATTRIBUTE, id, values, evaluator); }
From source file:org.swordess.ldap.util.ModUtils.java
public static ModificationItem remove(String id, Collection<?> values) { return create(DirContext.REMOVE_ATTRIBUTE, id, values, null); }
From source file:org.swordess.ldap.util.ModUtils.java
public static <T> ModificationItem remove(String id, Collection<?> values, Evaluator<T> evaluator) { return create(DirContext.REMOVE_ATTRIBUTE, id, values, evaluator); }
From source file:org.wso2.carbon.connector.ldap.UpdateEntry.java
@Override public void connect(MessageContext messageContext) throws ConnectException { String attributesString = (String) getParameter(messageContext, LDAPConstants.ATTRIBUTES); String dn = (String) getParameter(messageContext, LDAPConstants.DN); String mode = (String) getParameter(messageContext, LDAPConstants.MODE); OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace ns = factory.createOMNamespace(LDAPConstants.CONNECTOR_NAMESPACE, LDAPConstants.NAMESPACE); OMElement result = factory.createOMElement(LDAPConstants.RESULT, ns); OMElement message = factory.createOMElement(LDAPConstants.MESSAGE, ns); try {//from ww w . j a va 2s . c o m DirContext context = LDAPUtils.getDirectoryContext(messageContext); Attributes entry = new BasicAttributes(); if (StringUtils.isNotEmpty(attributesString)) { JSONObject object = new JSONObject(attributesString); Iterator keys = object.keys(); while (keys.hasNext()) { String key = (String) keys.next(); String val = object.getString(key); Attribute newAttr = new BasicAttribute(key); newAttr.add(val); entry.put(newAttr); } } try { if (mode.equals(LDAPConstants.REPLACE)) { context.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, entry); } else if (mode.equals(LDAPConstants.ADD)) { context.modifyAttributes(dn, DirContext.ADD_ATTRIBUTE, entry); } else if (mode.equals(LDAPConstants.REMOVE)) { context.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, entry); } message.setText(LDAPConstants.SUCCESS); result.addChild(message); LDAPUtils.preparePayload(messageContext, result); } catch (NamingException e) { // LDAP Errors are catched LDAPUtils.handleErrorResponse(messageContext, LDAPConstants.ErrorConstants.UPDATE_ENTRY_ERROR, e); throw new SynapseException(e); } } catch (NamingException e) { //Authentication failures are catched LDAPUtils.handleErrorResponse(messageContext, LDAPConstants.ErrorConstants.INVALID_LDAP_CREDENTIALS, e); throw new SynapseException(e); } catch (JSONException e) { handleException("Error while passing the JSON object", e, messageContext); } }