This is my second proposed patch; it's more involved and probably breaks the standard 
LDAP test cases. No CVS check in for this one - if someone could check how/if this 
breaks the standard test cases, I'll consider checking it in.

Reason for patch:
Attributes on Directory Servers can be either single-valued or multi-valued. The 
default LDAPSampler.java only allows for single-valued attributes due to the 
getUserAttributes() method. If you define four mail attributes, only the last one will 
be kept on the attrs structure.

Additionally, not all objects on LDAP servers have the full set of object classes 
defined in getUserAttributes().

Suggested patch:
This patch substantially changes the getUserAttributes() method. A base objectclass of 
top is kept as all entries in a Directory must inherit top. However, all other 
attributes and values must be entered by the user. This probably breaks the default 
add test.

The while loop has been modified to check for two possibilities:
1. The attribute matches the last one. In this case, add the value.
2. The attribute doesn't match the last one. In this case, check if the attribute has 
already been put() on the attrs structure.
  If it has been, add the new value to that attribute.
  If it has not been, it's a completely new attribute. Add the attribute and the value 
to attrs.

Actual code:
    public BasicAttributes getUserAttributes() {
        boolean add =true;
        BasicAttributes attrs = new BasicAttributes(true);
        PropertyIterator iter = getArguments().iterator();

        String lastSeen = "objectclass";
        BasicAttribute attr = new BasicAttribute("objectclass");
        attr.add("top");
        attrs.put(attr);
        while (iter.hasNext()) {
            Argument item = (Argument) iter.next().getObjectValue();
            String current = item.getName();
            if ( lastSeen.equalsIgnoreCase(current) ) {
                attr.add( item.getValue() );
            } else {
                //check if it's already been added to the attrs
                Attribute oldAttr = attrs.get(current);
                if (oldAttr == null) {
                        //this one is completely new, so add it to attrs
                        attrs.put(attr);
                        //make a note of it
                        lastSeen = current;
                        //get the next one
                        attr = getBasicAttribute( item.getName(),item.getValue());
                } else {
                        oldAttr.add( item.getValue() );
                        //overwrite existing value
                        attrs.remove(current);
                        attrs.put(oldAttr);
                        lastSeen = current;
                }
            }
        }
        //put the last one
        attrs.put(attr);
        return attrs;
    }

Regards,


Kayne McGladrey
AT&T Wireless

Reply via email to