use of org.forgerock.opendj.ldap.ModificationType 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.ModificationType 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);
}
Aggregations