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;
}
}
}
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);
}
}
}
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;
}
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);
}
}
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);
}
}
Aggregations