Search in sources :

Example 6 with ModificationItem

use of javax.naming.directory.ModificationItem in project OpenAM by OpenRock.

the class SMSLdapObject method copyModItemsToModifyRequest.

// Method to covert JNDI ModificationItems to LDAPModificationSet
private static ModifyRequest copyModItemsToModifyRequest(DN dn, ModificationItem[] mods) throws SMSException {
    ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(dn);
    try {
        for (ModificationItem mod : mods) {
            Attribute attribute = mod.getAttribute();
            LinkedAttribute attr = new LinkedAttribute(attribute.getID());
            for (NamingEnumeration ne = attribute.getAll(); ne.hasMore(); ) {
                attr.add(ne.next());
            }
            switch(mod.getModificationOp()) {
                case DirContext.ADD_ATTRIBUTE:
                    modifyRequest.addModification(new Modification(ModificationType.ADD, attr));
                    break;
                case DirContext.REPLACE_ATTRIBUTE:
                    modifyRequest.addModification(new Modification(ModificationType.REPLACE, attr));
                    break;
                case DirContext.REMOVE_ATTRIBUTE:
                    modifyRequest.addModification(new Modification(ModificationType.DELETE, attr));
                    break;
            }
        }
    } catch (NamingException nne) {
        throw new SMSException(nne, "sms-cannot-copy-fromModItemToModSet");
    }
    return modifyRequest;
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) Modification(org.forgerock.opendj.ldap.Modification) Attribute(javax.naming.directory.Attribute) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) SMSException(com.sun.identity.sm.SMSException) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute)

Example 7 with ModificationItem

use of javax.naming.directory.ModificationItem in project OpenAM by OpenRock.

the class SMSEmbeddedLdapObject method copyModItemsToLDAPModList.

// Method to covert JNDI ModificationItems to LDAPModificationSet
private static List copyModItemsToLDAPModList(ModificationItem[] mods) throws SMSException {
    if ((mods == null) || (mods.length == 0)) {
        return null;
    }
    List<LDAPModification> modList = new ArrayList<>(mods.length);
    try {
        for (ModificationItem mod : mods) {
            Attribute dAttr = mod.getAttribute();
            String attrName = dAttr.getID();
            List<String> values = new ArrayList<>();
            for (NamingEnumeration ne = dAttr.getAll(); ne.hasMore(); ) {
                values.add((String) ne.next());
            }
            ModificationType modType = null;
            switch(mod.getModificationOp()) {
                case DirContext.ADD_ATTRIBUTE:
                    modType = ModificationType.ADD;
                    break;
                case DirContext.REPLACE_ATTRIBUTE:
                    modType = ModificationType.REPLACE;
                    break;
                case DirContext.REMOVE_ATTRIBUTE:
                    modType = ModificationType.DELETE;
                    break;
            }
            if (modType != null) {
                modList.add(new LDAPModification(modType, new LDAPAttribute(attrName, values)));
            }
        }
    } catch (NamingException nne) {
        throw (new SMSException(nne, "sms-cannot-copy-fromModItemToModSet"));
    }
    return (modList);
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) LDAPAttribute(org.opends.server.protocols.ldap.LDAPAttribute) Attribute(javax.naming.directory.Attribute) LDAPAttribute(org.opends.server.protocols.ldap.LDAPAttribute) ModificationType(org.forgerock.opendj.ldap.ModificationType) SMSException(com.sun.identity.sm.SMSException) LDAPModification(org.opends.server.protocols.ldap.LDAPModification) ArrayList(java.util.ArrayList) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException)

Example 8 with ModificationItem

use of javax.naming.directory.ModificationItem in project OpenAM by OpenRock.

the class SMSEntry method removeAttribute.

/**
     * Remove the attribute from the entry.
     */
public void removeAttribute(String attrName) throws SMSException {
    Set attribute = (Set) attrSet.get(attrName);
    if (attribute == null) {
        throw (new SMSException(LdapException.newLdapException(ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, getBundleString(IUMSConstants.SMS_ATTR_OR_VAL_EXISTS)), "sms-ATTR_OR_VAL_EXISTS"));
    }
    attrSet.remove(attrName);
    if (modSet == null) {
        modSet = new HashSet();
    }
    BasicAttribute ba = new BasicAttribute(attrName, attribute);
    for (Iterator items = attribute.iterator(); items.hasNext(); ) ba.add(items.next());
    modSet.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, ba));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) Iterator(java.util.Iterator) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with ModificationItem

use of javax.naming.directory.ModificationItem in project OpenAM by OpenRock.

the class SMSJAXRPCObjectImpl method getModItems.

/**
     * Returns an array of ModificationItems converted from string
     * representation of mods. The string representation is of the format:
     * <pre>
     * <Modifications size="xx"> <AttributeValuePair event="ADD | REPLACE |
     * DELETE"> <Attribute name="attrName" /> <Value>...</Value>
     * </AttributeValuePair> </Modifications>
     * </pre>
     */
static ModificationItem[] getModItems(String mods) throws SMSException {
    if (debug.messageEnabled()) {
        debug.message("SMSJAXRPCObject::StringToMods: " + mods);
    }
    ModificationItem[] answer = null;
    try {
        if (mods != null) {
            mods = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + mods;
            Document doc = XMLUtils.toDOMDocument(mods, debug);
            Node root = XMLUtils.getRootNode(doc, "Modifications");
            int modsSize = Integer.parseInt(XMLUtils.getNodeAttributeValue(root, "size"));
            answer = new ModificationItem[modsSize];
            NodeList nl = root.getChildNodes();
            for (int i = 0; i < modsSize; i++) {
                Node node = nl.item(i);
                if (node.getNodeName().equals("AttributeValuePair")) {
                    String eventS = XMLUtils.getNodeAttributeValue(node, "event");
                    int event = DirContext.ADD_ATTRIBUTE;
                    if (eventS.equals("REPLACE"))
                        event = DirContext.REPLACE_ATTRIBUTE;
                    else if (eventS.equals("DELETE"))
                        event = DirContext.REMOVE_ATTRIBUTE;
                    Node attrNode = XMLUtils.getChildNode(node, "Attribute");
                    String attrName = XMLUtils.getNodeAttributeValue(attrNode, "name");
                    Set vals = XMLUtils.getAttributeValuePair(node, false);
                    // Construct ModificationItem
                    BasicAttribute attr = new BasicAttribute(attrName);
                    for (Iterator it = vals.iterator(); it.hasNext(); ) attr.add(it.next());
                    answer[i] = new ModificationItem(event, attr);
                }
            }
        }
    } catch (Exception e) {
        throw (new SMSException(e, "sms-JAXRPC-cannot-copy-fromModStringToModItem"));
    }
    return (answer);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) HashSet(java.util.HashSet) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) Document(org.w3c.dom.Document) JSONException(org.json.JSONException) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) SSOException(com.iplanet.sso.SSOException)

Example 10 with ModificationItem

use of javax.naming.directory.ModificationItem in project perun by CESNET.

the class LdapConnectorImpl method addMemberToGroup.

//-----------------------------MEMBER MODIFICATION METHODS--------------------
public void addMemberToGroup(Member member, Group group) throws InternalErrorException {
    //Add member to group
    Attribute uniqueMember = new BasicAttribute("uniqueMember", "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
    ModificationItem uniqueMemberItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, uniqueMember);
    this.updateGroup(group, new ModificationItem[] { uniqueMemberItem });
    //Add member to vo if this group is memebrsGroup
    if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
        //Add info to vo
        this.updateVo(group.getVoId(), new ModificationItem[] { uniqueMemberItem });
        //Add info also to user
        Attribute memberOfPerunVo = new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
        ModificationItem memberOfPerunVoItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOfPerunVo);
        this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfPerunVoItem });
    }
    //Add group info to member
    Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
    ModificationItem memberOfItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOf);
    this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfItem });
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute)

Aggregations

ModificationItem (javax.naming.directory.ModificationItem)23 BasicAttribute (javax.naming.directory.BasicAttribute)19 Attribute (javax.naming.directory.Attribute)12 ArrayList (java.util.ArrayList)5 NamingException (javax.naming.NamingException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)3 SMSException (com.sun.identity.sm.SMSException)3 Hashtable (java.util.Hashtable)3 LinkedHashSet (java.util.LinkedHashSet)3 Attributes (javax.naming.directory.Attributes)3 DirContext (javax.naming.directory.DirContext)3 LdapOperationException (org.codelibs.fess.exception.LdapOperationException)3 Base64 (java.util.Base64)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Locale (java.util.Locale)2