Search in sources :

Example 11 with BasicAttribute

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);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 12 with BasicAttribute

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));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) Iterator(java.util.Iterator) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 13 with BasicAttribute

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);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) HashSet(java.util.HashSet) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) Document(org.w3c.dom.Document) JSONException(org.json.JSONException) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) SSOException(com.iplanet.sso.SSOException)

Example 14 with BasicAttribute

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;
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingException(javax.naming.NamingException)

Example 15 with BasicAttribute

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);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) NameNotFoundException(org.springframework.ldap.NameNotFoundException) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

BasicAttribute (javax.naming.directory.BasicAttribute)44 Attribute (javax.naming.directory.Attribute)28 BasicAttributes (javax.naming.directory.BasicAttributes)25 Attributes (javax.naming.directory.Attributes)17 ModificationItem (javax.naming.directory.ModificationItem)17 HashSet (java.util.HashSet)14 File (java.io.File)7 Set (java.util.Set)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 DirContext (javax.naming.directory.DirContext)5 Test (org.junit.Test)5 PrivkeySchema (org.nhindirect.ldap.PrivkeySchema)5 Collections (java.util.Collections)4 Date (java.util.Date)3 Enumeration (java.util.Enumeration)3