use of javax.naming.directory.BasicAttribute in project OpenAM by OpenRock.
the class SMSEntry method setAttribute.
/**
* Set the attribute values. <code>save()</code> must be called to make
* the changes persistant
*/
public void setAttribute(String attrName, String[] attrValues) {
// Attribute Values to be Set and BasicAttribute
Set attrs = new HashSet();
BasicAttribute ba = new BasicAttribute(attrName);
for (int i = 0; attrValues != null && i < attrValues.length; i++) {
attrs.add(attrValues[i]);
ba.add(attrValues[i]);
}
// Check if attrSet, modSet is present, if not create
attrSet = (attrSet == null) ? (new CaseInsensitiveHashMap()) : attrSet;
modSet = (modSet == null) ? (new HashSet()) : modSet;
// Check if the attribute exists, if not present add, else replace
if (!attrSet.containsKey(attrName)) {
// Not present: add it, update modset
modSet.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, ba));
} else {
// Remove old attrbute and add the new attribute, update modset
modSet.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, ba));
}
// Update attrset
attrSet.put(attrName, attrs);
}
use of javax.naming.directory.BasicAttribute 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.BasicAttribute 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.BasicAttribute in project yyl_example by Relucent.
the class LdapDaoHelper method create.
/**
* 创建新条目
* @param entry 新条目
* @param ctx LDAP上下文连接
* @deprecated 该方法未经过严谨测试
*/
public static void create(LdapEntry entry, LdapContext ctx) throws NamingException {
try {
String dn = entry.getDn();
Attributes attrs = new BasicAttributes(true);
if (entry != null && !entry.isEmpty()) {
Iterator<String> iterator = entry.keySet().iterator();
while (iterator.hasNext()) {
String id = iterator.next();
Attribute attr = new BasicAttribute(id);
List<?> values = entry.getAll(id);
if (values != null) {
for (Object value : values) {
attr.add(value);
}
}
attrs.put(attr);
}
}
ctx.createSubcontext(dn, attrs);
} catch (NamingException e) {
throw e;
}
}
use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method createResource.
//------------------RESOURCE MODIFICATION METHODS----------------------------
public void createResource(Resource resource, String entityID) throws InternalErrorException {
// Create a set of attributes
Attributes attributes = new BasicAttributes();
// Create the objectclass to add
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("perunResource");
// Add attributes
attributes.put(objClasses);
attributes.put("cn", resource.getName());
attributes.put("perunResourceId", String.valueOf(resource.getId()));
attributes.put("perunFacilityId", String.valueOf(resource.getFacilityId()));
attributes.put("perunVoId", String.valueOf(resource.getVoId()));
if (resource.getDescription() != null && !resource.getDescription().isEmpty())
attributes.put("description", resource.getDescription());
// get info about entityID attribute if exists
if (entityID != null)
attributes.put("entityID", entityID);
// Create the entry
try {
ldapTemplate.bind(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId())), null, attributes);
log.debug("New entry created in LDAP: Resource {} in Vo with Id=" + resource.getVoId() + " and Facility with ID=" + resource.getFacilityId() + ".", resource);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
Aggregations