Announcement Announcement Module
Collapse
No announcement yet.
Wanna retreive emailId using the windows login user name from ldap active directory. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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, 06:13 AM.

    Comment

    Working...
    X