You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jamalissimo <ro...@gmail.com> on 2013/06/12 13:09:56 UTC

LDAP component - search for multiple users

Hello guys,

I am now trying to add functionality for searching multiple users to our
project. We already have code which returns data for single user. From the
begining it looked quite easy. I will just send request like
(|(uid=user1)(uid=user2)) to LDAP. This actually works and I can see in
karaf.log, that I received data for these two users. 

I am using this converter to pass data to POJO class

    @Converter
    public static LdapPerson toLdapPerson(Collection ldapResult) {

        Iterator<?> resultIterator = ldapResult.iterator();
        SearchResult searchResult = (SearchResult) resultIterator.next();

        Attributes attributes = searchResult.getAttributes();
        Attribute uidAttribute = attributes.get("uid");
        Attribute givenNameAttribute = attributes.get("givenname");
        Attribute snAttribute = attributes.get("sn");
        Attribute cnAttribute = attributes.get("cn");
        Attribute mailAttribute = attributes.get("mail");

        String uid = getAttributeValue(uidAttribute);
        String givenName = getAttributeValue(givenNameAttribute);
        String sn = getAttributeValue(snAttribute);
        String cn = getAttributeValue(cnAttribute);
        String email = getAttributeValue(mailAttribute);

        LdapPerson ldapPerson = new LdapPerson();
        ldapPerson.setUid(uid);
        ldapPerson.setGivenName(givenName);
        ldapPerson.setSurname(sn);
        ldapPerson.setCommonName(cn);
        ldapPerson.setEmail(email);

        return ldapPerson;
    }

For single user it works perfectly, but when I have more then one user, then
it shows data only for the first one. 
When I modified the converter to loop through ldapResult, it was the same,
because I receive only one big message which contains two results. I tried
splitter, but I was getting errors.

This is the message I get:

BodyType:java.util.ArrayList, Body:[uid=user1: null:null:{mail=mail:
user1@company.com, uid=uid: user1, objectclass=objectClass: top, person,
organizationalPerson, inetorgperson, givenname=givenName: user1, sn=sn:
user1,cn=cn: user1 user1}, uid=user2: null:null:{mail=mail:
user2@company.com, uid=uid: user2, objectclass=objectClass: top, person,
organizationalPerson, inetorgperson, givenname=givenName: user2, sn=sn:
user2,cn=cn: user2 user2}]

Thanks for help

-Roman



--
View this message in context: http://camel.465427.n5.nabble.com/LDAP-component-search-for-multiple-users-tp5734130.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: LDAP component - search for multiple users

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Your type converter returns a LdapPerson which is not a List so there
is always only that typed returned.

You would need to use a @FallbackTypeConverter and convert to a List
of LdapPerson.
http://camel.apache.org/type-converter.html

But instead of using type converters, you can also just use a java
bean with a method to do a message translation from ldap result to a
list of persons.
http://camel.apache.org/message-translator.html

On Wed, Jun 12, 2013 at 1:09 PM, jamalissimo <ro...@gmail.com> wrote:
> Hello guys,
>
> I am now trying to add functionality for searching multiple users to our
> project. We already have code which returns data for single user. From the
> begining it looked quite easy. I will just send request like
> (|(uid=user1)(uid=user2)) to LDAP. This actually works and I can see in
> karaf.log, that I received data for these two users.
>
> I am using this converter to pass data to POJO class
>
>     @Converter
>     public static LdapPerson toLdapPerson(Collection ldapResult) {
>
>         Iterator<?> resultIterator = ldapResult.iterator();
>         SearchResult searchResult = (SearchResult) resultIterator.next();
>
>         Attributes attributes = searchResult.getAttributes();
>         Attribute uidAttribute = attributes.get("uid");
>         Attribute givenNameAttribute = attributes.get("givenname");
>         Attribute snAttribute = attributes.get("sn");
>         Attribute cnAttribute = attributes.get("cn");
>         Attribute mailAttribute = attributes.get("mail");
>
>         String uid = getAttributeValue(uidAttribute);
>         String givenName = getAttributeValue(givenNameAttribute);
>         String sn = getAttributeValue(snAttribute);
>         String cn = getAttributeValue(cnAttribute);
>         String email = getAttributeValue(mailAttribute);
>
>         LdapPerson ldapPerson = new LdapPerson();
>         ldapPerson.setUid(uid);
>         ldapPerson.setGivenName(givenName);
>         ldapPerson.setSurname(sn);
>         ldapPerson.setCommonName(cn);
>         ldapPerson.setEmail(email);
>
>         return ldapPerson;
>     }
>
> For single user it works perfectly, but when I have more then one user, then
> it shows data only for the first one.
> When I modified the converter to loop through ldapResult, it was the same,
> because I receive only one big message which contains two results. I tried
> splitter, but I was getting errors.
>
> This is the message I get:
>
> BodyType:java.util.ArrayList, Body:[uid=user1: null:null:{mail=mail:
> user1@company.com, uid=uid: user1, objectclass=objectClass: top, person,
> organizationalPerson, inetorgperson, givenname=givenName: user1, sn=sn:
> user1,cn=cn: user1 user1}, uid=user2: null:null:{mail=mail:
> user2@company.com, uid=uid: user2, objectclass=objectClass: top, person,
> organizationalPerson, inetorgperson, givenname=givenName: user2, sn=sn:
> user2,cn=cn: user2 user2}]
>
> Thanks for help
>
> -Roman
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/LDAP-component-search-for-multiple-users-tp5734130.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen