Results 1 to 2 of 2

Thread: Wanna retreive emailId using the windows login user name from ldap active directory.

  1. #1

    Default Wanna retreive emailId using the windows login user name from ldap active directory.

    Hi,

    I am able to connect to my ldap server but after connecting i get an exception when i try n search for a user.
    Code:
         SearchControls constraints = new SearchControls();
    
                    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
                    String[] attrIDs = { "distinguishedName",
                            "sn",
                            "givenname",
                            "mail",
                            "telephonenumber"};
                    constraints.setReturningAttributes(attrIDs);
                    //First input parameter is search base, it can be "CN=Users,DC=YourDomain,DC=com"
                    //Second Attribute can be uid=username
                    NamingEnumeration<SearchResult> answer = ctx.search("CN=Harish Patharla,OU=IG**,OU=IG**,OU=IG Users,DC=***,DC=**,DC=***", "igi\\patharh" + username, constraints);
                    System.out.println("username =" + username);
    After successful connection here is what the stack trace looks like:
    Code:
    Connection Successful.
    javax.naming.directory.InvalidSearchFilterException: Missing 'equals'; remaining name 'CN=Harish Patharla,OU=IG**,OU=IG**,OU=IGUsers,DC=***,DC=**,DC=***'
    	at com.sun.jndi.ldap.Filter.encodeSimpleFilter(Filter.java:310)
    	at com.sun.jndi.ldap.Filter.encodeFilter(Filter.java:152)
    	at com.sun.jndi.ldap.Filter.encodeFilterString(Filter.java:56)
    	at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:520)
    	at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1962)
    Could any one please help me with what i am doing wrong here?

  2. #2

    Default

    The parameters i was passing into ctx.search() were wrong.I am getting response now with the asked details.

    String[] attrIDs = { "distinguishedName",
    "sn",
    "givenname",
    "mail",
    "telephonenumber"};

    But now i get an exception as below:
    java.lang.NullPointerException
    at com.sun.jndi.ldap.LdapNamingEnumeration.getNextBat ch(LdapNamingEnumeration.java:111)
    at com.sun.jndi.ldap.LdapNamingEnumeration.nextAux(Ld apNamingEnumeration.java:245)
    at com.sun.jndi.ldap.LdapNamingEnumeration.nextImpl(L dapNamingEnumeration.java:236)
    at com.sun.jndi.ldap.LdapNamingEnumeration.next(LdapN amingEnumeration.java:184)
    The line where its throwing the above exception is :
    Attributes attrs = ((SearchResult) answer.next()).getAttributes();

    I added a null check but it doesnot seem to work
    if(!((SearchResult) answer.next()).getAttributes().equals(null)){

    Attributes attrs = ((SearchResult) answer.next()).getAttributes();
    }
    Can anyone help me out with what is wrong?
    Last edited by harishpatarla; Nov 26th, 2012 at 06:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •