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