Search in sources :

Example 1 with Modification

use of org.forgerock.opendj.ldap.Modification in project OpenAM by OpenRock.

the class ModSet method remove.

/**
     * Removes the first attribute with the specified name in the set of modifications.
     * @param name name of the attribute to remove
     */
public synchronized void remove(String name) {
    for (int i = 0; i < modifications.size(); i++) {
        Modification mod = modifications.get(i);
        Attribute attr = mod.getAttribute();
        if (name.equalsIgnoreCase(attr.getAttributeDescriptionAsString())) {
            modifications.remove(i);
            return;
        }
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attribute(org.forgerock.opendj.ldap.Attribute)

Example 2 with Modification

use of org.forgerock.opendj.ldap.Modification in project OpenAM by OpenRock.

the class DataLayer method modify.

/**
     * Modifies an ldap entry.
     * 
     * @param principal Authentication Principal.
     * @param guid globally unique identifier for the entry.
     * @param modifications Set of modifications for the entry.
     * @exception AccessRightsException if insufficient access
     * @exception EntryNotFoundException if the entry is not found.
     * @exception UMSException if failure
     *
     * @supported.api
     */
public void modify(Principal principal, Guid guid, Collection<Modification> modifications) throws UMSException {
    String id = guid.getDn();
    ResultCode errorCode;
    try {
        ModifyRequest request = LDAPRequests.newModifyRequest(id);
        for (Modification modification : modifications) {
            request.addModification(modification);
        }
        int retry = 0;
        while (retry <= connNumRetry) {
            if (debug.messageEnabled()) {
                debug.message("DataLayer.modify retry: " + retry);
            }
            try (Connection conn = getConnection(principal)) {
                conn.modify(request);
                return;
            } catch (LdapException e) {
                if (!retryErrorCodes.contains("" + e.getResult().getResultCode().toString()) || retry == connNumRetry) {
                    throw e;
                }
                retry++;
                try {
                    Thread.sleep(connRetryInterval);
                } catch (InterruptedException ex) {
                }
            }
        }
    } catch (LdapException e) {
        if (debug.warningEnabled()) {
            debug.warning("Exception in DataLayer.modify for DN: " + id, e);
        }
        errorCode = e.getResult().getResultCode();
        if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
            throw new EntryNotFoundException(id, e);
        } else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
            throw new AccessRightsException(id, e);
        } else {
            throw new UMSException(id, e);
        }
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 3 with Modification

use of org.forgerock.opendj.ldap.Modification 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 4 with Modification

use of org.forgerock.opendj.ldap.Modification in project OpenAM by OpenRock.

the class DJLDAPv3Repo method modifyGroupMembership.

/**
     * Modifies group membership data in the directory. In case the memberOf attribute is configured, this will also
     * iterate through all the user entries and modify those as well. Otherwise this will only modify the uniquemember
     * attribute on the group entry based on the operation.
     *
     * @param groupDN The DN of the group.
     * @param memberDNs The DNs of the group members.
     * @param operation Whether the members needs to be added or removed from the group. Use {@link IdRepo#ADDMEMBER}
     * or {@link IdRepo#REMOVEMEMBER}.
     * @throws IdRepoException If there was an error while modifying the membership data.
     */
private void modifyGroupMembership(String groupDN, Set<String> memberDNs, int operation) throws IdRepoException {
    ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(groupDN);
    Attribute attr = new LinkedAttribute(uniqueMemberAttr, memberDNs);
    ModificationType modType;
    if (ADDMEMBER == operation) {
        modType = ModificationType.ADD;
    } else {
        modType = ModificationType.DELETE;
    }
    modifyRequest.addModification(new Modification(modType, attr));
    Connection conn = null;
    try {
        conn = connectionFactory.getConnection();
        conn.modify(modifyRequest);
        if (memberOfAttr != null) {
            for (String member : memberDNs) {
                ModifyRequest userMod = LDAPRequests.newModifyRequest(member);
                userMod.addModification(modType, memberOfAttr, groupDN);
                conn.modify(userMod);
            }
        }
    } catch (LdapException ere) {
        DEBUG.error("An error occurred while trying to modify group membership. Name: " + groupDN + " memberDNs: " + memberDNs + " Operation: " + modType, ere);
        handleErrorResult(ere);
    } finally {
        IOUtils.closeIfNotNull(conn);
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attribute(org.forgerock.opendj.ldap.Attribute) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) ModificationType(org.forgerock.opendj.ldap.ModificationType) Connection(org.forgerock.opendj.ldap.Connection) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) ByteString(org.forgerock.opendj.ldap.ByteString) LdapException(org.forgerock.opendj.ldap.LdapException) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute)

Example 5 with Modification

use of org.forgerock.opendj.ldap.Modification in project OpenAM by OpenRock.

the class DJLDAPv3Repo method modifyRoleMembership.

/**
     * Modifies role membership data in the directory. This will add/remove the corresponding nsRoleDN attribute from
     * the user entry.
     *
     * @param roleDN The DN of the role.
     * @param memberDNs The DNs of the role members.
     * @param operation Whether the members needs to be added or removed from the group. Use {@link IdRepo#ADDMEMBER}
     * or {@link IdRepo#REMOVEMEMBER}.
     * @throws IdRepoException If there was an error while modifying the membership data.
     */
private void modifyRoleMembership(String roleDN, Set<String> memberDNs, int operation) throws IdRepoException {
    Attribute attr = new LinkedAttribute(roleDNAttr, roleDN);
    Modification mod;
    if (ADDMEMBER == operation) {
        mod = new Modification(ModificationType.ADD, attr);
    } else {
        mod = new Modification(ModificationType.DELETE, attr);
    }
    Connection conn = null;
    try {
        conn = connectionFactory.getConnection();
        for (String memberDN : memberDNs) {
            ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(memberDN);
            modifyRequest.addModification(mod);
            conn.modify(modifyRequest);
        }
    } catch (LdapException ere) {
        DEBUG.error("An error occurred while trying to modify role membership. Name: " + roleDN + " memberDNs: " + memberDNs, ere);
        handleErrorResult(ere);
    } finally {
        IOUtils.closeIfNotNull(conn);
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attribute(org.forgerock.opendj.ldap.Attribute) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute)

Aggregations

Modification (org.forgerock.opendj.ldap.Modification)13 LdapException (org.forgerock.opendj.ldap.LdapException)7 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)7 Attribute (org.forgerock.opendj.ldap.Attribute)6 ByteString (org.forgerock.opendj.ldap.ByteString)6 Connection (org.forgerock.opendj.ldap.Connection)5 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)4 Attr (com.iplanet.services.ldap.Attr)2 HashSet (java.util.HashSet)2 ResultCode (org.forgerock.opendj.ldap.ResultCode)2 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 Debug (com.sun.identity.shared.debug.Debug)1 SMSException (com.sun.identity.sm.SMSException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1